0

I have an ordinary C# windows service that crawls web pages and I am experiencing a similar issue to the issue described here: An existing connection was forcibly closed by the remote host - WCF

Can I use the Service Trace Viewer Tool for an ordinary windows service (it's not wcf) or is there an alternative tracing utility I can use?

Community
  • 1
  • 1
Imran Azad
  • 1,008
  • 2
  • 12
  • 30
  • Add log4net to your service, and log the exceptions to a file. – dbugger Jan 10 '15 at 22:45
  • @dbugger, unless you are hooking into WCF via extensibility points, you would not ever receive an exception to log. Log4net does not seem to have a `TraceListener` for this purpose either. See http://stackoverflow.com/questions/515381/how-to-log-trace-messages-with-log4net – Mitch Jan 10 '15 at 23:26

1 Answers1

4

Yes, you can add the listener by adding a system.diagnostics configuration section to your app.config. Add the following configuration section and point the log file to a writable path.

App.config:

<configuration>
  <!-- ... -->
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Error" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener"
            initializeData="c:\drop\servicename wcferror.svclog"/>
        </listeners>
      </source>
    </sources>
    <trace autoflush="true"></trace>
  </system.diagnostics>
</configuration>

If you prefer to log to the event log, you can use System.Diagnostics.EventLogTraceListener in lieu of System.Diagnostics.XmlWriterTraceListener. The initializeData is then the log name.

Mitch
  • 21,223
  • 6
  • 63
  • 86