Thursday, March 28, 2013

Windows Service logging

Assuming a class inheirts from ServiceBase it could "write to the logs" like so:

private System.Diagnostics.EventLog eventLog;
eventLog = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(eventLog)).BeginInit();
eventLog.Log = "Application";
eventLog.Source = "FooService";
((System.ComponentModel.ISupportInitialize)(eventLog)).EndInit();
eventLog.WriteEntry("look at this");

No comments:

Post a Comment