Search code examples
c#.netevent-logevent-listener

Diagnostic Logging


Apologies if this has been asked before.

I have recently enabled the diagnostics messagelogging on our C# solution. However, the example I got from the web, the standard, has, I think, too many events being logged.

Can I adjust this messagelogger to log just the critical errors experienced in the system? I am still new at this message logging, so if I knew what to do, I wouldn't be asking you guys.

My current setup:

 <system.serviceModel>
<diagnostics>
  <!-- Enable Message Logging here. -->
  <!-- log all messages received or sent at the transport or service model levels >-->
  <messageLogging logEntireMessage="true" maxMessagesToLog="300" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>

<system.diagnostics>
<sources>
  <source name="System.ServiceModel" switchValue="Information,ActivityTracing" propagateActivity="true">
    <listeners>
      <add name="xml" />
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging">
    <listeners>
      <add name="xml" />
    </listeners>
  </source>
</sources>
<sharedListeners>
  <add initializeData="C:\logs\Diagnostics.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml" />
</sharedListeners>
<trace autoflush="true" />

All this is of course in my App.config. I only use it here, and not in my code or anywhere else. It works, but to me, there is too much info being saved. Could I just save the major/critical errors?

C# project, Visual Studio 2015, Windows 10. If you need more, please ask.


Solution

  • Within you <source> node change the value of the attribute switchValue to Critical, Error then this should only log those events. Information is an event that generally occurs everywhere on tracing.

    You can maybe also look here to gain further information about the logging: From zero to logging