Be careful, EventSource classes must be sealed! If you want to use dependency injection using EventSource , there is a workaround ...
Define a simple interface:
And implementation (the implementation of your interface should be decorated with NonEventAttribute :
[EventSource(Name = "MyLogEventsource")] public class Log : EventSource, ILog { public Log() { EventSourceAnalyzer.InspectAll(this); } [NonEvent] public void Debug(string message) { DebugInternal(message); } [Event(1)] private void DebugInternal(string message) { WriteEvent(1, message); } [NonEvent] public void Info(string message) { InfoInternal(message); } [Event(2)] private void InfoInternal(string message) { WriteEvent(2, message); } [NonEvent] public void Warn(string message) { WarnInternal(message); } [Event(3)] private void WarnInternal(string message) { WriteEvent(3, message); } [NonEvent] public void Error(string message) { ErrorInternal(message, "", ""); } [NonEvent] public void Error(string message, Exception exception) { ErrorInternal(message, exception.Message, exception.ToString()); } [Event(4)] private void ErrorInternal(string message, string exceptionMessage, string exceptionDetails) { WriteEvent(4, message, exceptionMessage, exceptionDetails); } }
you can now enter the logging class ^^
Thomas
source share