1

I have a C# application with NLog for logging and it's set up to also log messages sent to System.Diagnostics's Trace/Debug system. This is done in the application's config file like this:

<system.diagnostics>
  <trace autoflush="true" indentsize="2">
    <listeners>
      <add name="nLogListener" />
    </listeners>
  </trace>

  <sources>
    <!--bunch of extra sources here-->
  </sources>

  <sharedListeners>
    <add name="nLogListener" type="NLog.NLogTraceListener, NLog"/>
  </sharedListeners>
</system.diagnostics>

This works all nicely, but since I started using AvalonDock the logs get cluttered with debugging info. I guess the assembly, pulled in via nuGet, was compiled with the DEBUG constant defined so the calls to Deug.WriteLine that are all over the AvalonDock source make it to the NLog log eventually. They look like this btw:

NLog.LoggerImpl.Write | Attach() 
NLog.LoggerImpl.Write | DockingManager.OnPreviewGotKeyboardFocus(System.Windows.Controls.Canvas) 
NLog.LoggerImpl.Write | SetFocusOnLastElement(focused=True, model=Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable, element=System.Windows.Controls.Canvas) 
NLog.LoggerImpl.Write | DockingManager.OnPreviewLostKeyboardFocus(System.Windows.Controls.Canvas) 

I'd like to exclude them while still maintaining all other messages sent to the trace. I could add a filter to NLog to exclude all of them using wildcards etc, but I'd rather don't do that since:

  • it requires me to figure out all possible messages AvalonDock can spit out
  • if AvalonDock changes, I have to update the filter
  • there's a risk of also excluding non-AvalonDock messages

Is there another way to handle this (without recompiling AvalonDock's source)? Can I somehow exclude all messages originating from a specific assembly? Or maybe have them prefixed with a known string so I can filter messages based on a single string?

stijn
  • 34,664
  • 13
  • 111
  • 163
  • There are some interesting notes in somewhat [related question](http://stackoverflow.com/q/4144394/395718). – Dialecticus Oct 31 '13 at 16:23
  • There's interesting info in remarks section of [TraceSource](http://msdn.microsoft.com/en-us/library/system.diagnostics.tracesource.aspx) class. – Dialecticus Oct 31 '13 at 16:38
  • @Dialecticus interesting indeed but unfortunately AvalonDock doesn't use `TraceSource`s but plain `Debug.WriteLine`, so I don't think the info applies to this case? – stijn Oct 31 '13 at 16:54

0 Answers0