When learning to create custom configuration in LogViewPlus it is helpful to begin with the sample code projects. This tutorial will assume that you have downloaded and run the sample projects successfully. Please see running the samples for more information.
Occasionally, when you are developing custom plugins for LogViewPlus you may find that the built in configuration options are insufficient. Beginning in LogViewPlus 2.3.8, we introduced the ICustomConfiguration interface. Implementing this interface on your custom filter, parser or reader will allow you to execute your own configuration code on the LogViewPlus UI thread.
The ICustomConfiguration interface is very simple. It takes an IWin32Window parent object as well as a string representing the existing configuration. Using this, you can show a WinForms dialog to modify or create the desired configuration. Once the necessary changes have been made, the new configuration should be returned from the method as a string. LogViewPlus will then manage configuration persistence in exactly the same way as any other filter, parser or reader. Your custom object will receive the configuration string as a parameter to the Initialize method.
The API has three parts:
ParentWindow - An IWin32Window object which can be used to display a child form. The type is set as object for simplicity, but the object can be safely cast if needed.
Configuration - The string used to represent the target configuration or Null if a new configuration is requested.
Return String - The configuration string that should ultimately be passed to your target filter, parser or reader. We recommend a base64 string for advanced configuration.
This interface will always be called from the UI thread. This allows you freely create UI components and control the user experience by blocking if necessary.
Our sample projects contain several examples of using the ICustomConfiguration interface. For our discussion, we will focus on the implementation contained in MyParser.cs. This implementation simply calls into a new OpenFileDialog instance - this keeps the GUI aspects of this configuration simple.
MyParser implements the following ICustomConfiguration.Configure method:
Here, we cast our parentWindow to an IWin32Window and use this as the parent for a new OpenFileDialog. The file name selected by the dialog is passed back as a configuration result. Alternatively, if the configuration dialog is cancelled, we can return the received configuration or a default value.
When our ICustomConfiguration interface is detected on a custom parser or reader you will find a new configuration command in the standard parser configuration dialog:
Clicking on this command will execute the custom configuration. When custom configuration is set, the target must be configured using the configuration provided. The parser arguments box will remain disabled. This area will only be used for argument display.
If the ICustomConfiguration interface is detected on a custom filter then you will find a new configuration command in the custom filter configuration dialog:
When custom configuration is set, the target must be configured using the configuration provided. The filter arguments box will remain disabled. This area will only be used for argument display.
Implementing custom configuration in LogViewPlus is relatively straight forward. If you have any questions or comments please feel free to contact us.