Reputation: 30215
I've followed the log4net advice given here. Then I'm launching MsTest unit tests by hitting 'F5' in Visual Studio 2010. When a unit test executes these two lines:
log.Warn("hello"); //this is a log4net logger.
System.Diagnostics.Debug.Write("there");
...the Visual Studio output window shows only the word "there." Why is "hello" not output?
When I debug-hover over the 'log' variable, it shows me:
IsDebugEnabled = false
IsErrorEnabled = true
IsFatalEnabled = true
IsInfoEnabled = false
IsWarnEnabled = true
From this I conclude that the configuration file is being read correctly. My log4net configuration looks like this:
<log4net>
<appender name="A1" type="log4net.Appender.OutputDebugStringAppender">
<!-- A1 uses PatternLayout -->
<layout type="log4net.Layout.PatternLayout">
<!--<conversionPattern value="%-4r [%t] %-5p %c %x - %m%n" />-->
<conversionPattern value="[MySite] %level %date{HH:mm:ss,fff} - %message%n" />
</layout>
</appender>
<root>
<level value="WARN" />
<appender-ref ref="A1" />
</root>
</log4net>
When I add an additional FileAppender, the file it creates does indeed have the "hello" message in it. Any clues why the VS debug output window isn't showing "hello"?
Upvotes: 3
Views: 2694
Reputation: 16077
Try using DebugAppender rather than OutputDebugStringAppender.
DebugAppender will end up as call to System.Diagnostics.Debug.Write
whereas OutputDebugStringAppender is calling unmanaged code and Visual Studio won't capture it (at least not by default and even then only when debugging, which means it won't work for your case).
Output from DebugAppender can also be captured using DebugView that is mentioned in the linked article, so I can't think of any reason he is are using OutputDebugStringAppender.
Upvotes: 8