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?