Best practices for logging information and error messages from an NT service?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've writing an NT service (on Vista) that will perform various housekeeping
activities throughout the day. This will be used by others in my
organization. To assist in the inevitable troubleshooting, I'd like the
service to log various error and status messages - so I can keep tabs on
what the service has done.

Is the Windows EventLog the appropriate place to store this information? Or
is that generally used for other things? I could obviously write my own
logging system, but don't want to reinvent the wheel if that's exactly what
the EventLog is there for.
 
Hello,

I ususally use TraceSources for this.

My application.config for a project of mine has these entries:

<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="infinitec.exchange.eventing"
switchName="verbosity"
switchType="System.Diagnostics.SourceSwitch" />
<sharedListeners>
<add name="xmlLog"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="xmlOutput.svclog" />
</sharedListeners>
<switches>
<add name="verbosity" value="All"/>
</switches>
</system.diagnostics>

In my application, I create a TraceSource instance with
TraceSource _Trace = new TraceSource("infinitec.exchange.eventing");

and then I call _Trace.TraceEvent.

The beauty here is that all errors are written to the event log and all
other messages are written to a xml trace log. This can be examined with the
Service Trace Viewer that comes with the SDK.

Kind regards,
Henning Krause
 
Back
Top