I am trying to use ETW to log errors/exceptions in my service.
The event source is pretty basic:
public class Logger : EventSource
{
public static readonly Logger Instance = new Logger();
// Use default trace listener so only profiler sees this data
// it will not be part of Tako
private Logger()
{
// Do nothing, but make the constuct private so static singleton use is enforced
}
[Event(EventId.StoreValueException, Level = EventLevel.Critical)]
public void CriticalException(Exception ex, int eventId)
{
WriteEvent(eventId, ex);
}
[Event(EventId.StoreValueException, Level = EventLevel.Error)]
public void Exception(Exception ex, int eventId)
{
WriteEvent(eventId, ex);
}
[Event(EventId.StoreValueException, Level = EventLevel.Warning)]
internal void Warning(string p, params object[] paramList)
{
WriteEvent(EventId.StoreValueLog, String.Format(p, paramList));
}
[Event(EventId.StoreValueException, Level = EventLevel.Informational)]
public void Info(string p, params object[] paramList)
{
WriteEvent(EventId.StoreValueLog, String.Format(p, paramList));
}
[Event(EventId.StoreValueException, Level = EventLevel.Verbose)]
public void Verbose(string p, params object[] paramList)
{
WriteEvent(EventId.StoreValueLog, String.Format(p, paramList));
}
}
Now I am trying to use that source to log to a file:
<system.diagnostics>
<sources>
<source name="MyNameSpace" switchValue="All" >
<listeners>
<add name="ErrorLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\ap\app\test\logs\fullweb.log"
type="System.Diagnostics.TextWriterTraceListener" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\ap\app\test\logs\errors.log"
type="System.Diagnostics.TextWriterTraceListener" name="ErrorLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<diagnostics performanceCounters="All" >
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" />
</diagnostics>
</system.serviceModel>
So the system.serviceModel logging works, but my event source logging doesn't. I feel like I have to set something to tell the listener to log everything. SwitchValue=All doesn't seem to be doing the trick