I'm working on program that is able to load various (self-made) plugins.
These Plugins need to have a way to send notifications to the host program.
Currently I have an Interface as a base for the plugins. The Interface defines an event that is fired whenever I need to log something
The Interface looks like this:
public delegate void LogEventHandler(object sender, LogEventArgs e);
public interface IWatcherPluginBase
{
event LogEventHandler WriteLog;
string Name { get; }
string Description { get; }
string Contact { get; }
Version Version { get; }
PluginState Status { get; }
string StatusDescription { get; }
void Start();
void Stop();
}
In the plugin I use the following code to fire the event
if (WriteLog != null)
WriteLog(this, new LogEventArgs("Started", MessageLevel.Info));
My main program adds an event handler
plugin.WriteLog += new LogEventHandler(plugin_WriteLog);
Do you know other (potentially better) ways to implement logging?
You might consider usign built-in classes in the namespace System.Diagnostics
(Debug
, Debugger
, Trace
, EventLog
).
That way you could redirect standard debug and trace output to VS console (when debugging) or to a file (when running a release build).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With