Dean Hiller
Dean Hiller

Reputation: 20182

VS 2010 log4net MSTest MSUnit not logging to console(but logs to file fine)

This ends up boiling down to the simple question of why does Console.WriteLine("asdfasdf") not get output to the output window in Visual Studio 2010??? as mine is not being output there when running tests.

I have a log configuration file that when I run my program in debug mode logs to file AND logs to the VS output window both. This same file when I use it with MS Test logs to the file I specify which ends up as TestResults/xxxx/example.log BUT does not log to the VS output pane. Why is that? This is very very annoying as I like to use the output to scroll through the logs.

My config in the log4net which works in one and not the other

 <log4net>
    <!-- A1 is set to be a ConsoleAppender -->
    <appender name="Console" type="log4net.Appender.ConsoleAppender">

        <!-- A1 uses PatternLayout -->
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message%newline" />
        </layout>
    </appender>

  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="example.log" />
    <appendToFile value="true" />
    <maximumFileSize value="100KB" />
    <maxSizeRollBackups value="2" />

    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%level %thread %logger - %message%newline" />
    </layout>
  </appender>

  <root>
    <level value="DEBUG" />
    <appender-ref ref="Console" />
    <appender-ref ref="RollingFile" />
  </root>

</log4net>

I call this in my test case

        // Set up a simple configuration that logs on the console.
        //BasicConfigurator.Configure();
        XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config"));
        Log.Info("testing");

I call this in my program because it is actually moved into bin\Debug\conf dir....

        XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("conf/log4net.config"));

        log.Info("Starting the toolbar application");

It makes absolutely no sense to me as to why this would not work?
thanks, Dean

Upvotes: 1

Views: 1177

Answers (1)

Marc L.
Marc L.

Reputation: 3399

I don't think the output pane actually reflects console output. Instead, in the "Test Results" pane, right click the test question and select "View Test Results Details" from the context menu. The results details for each test contains the console output for that test.

Also, thanks, I was having the opposite problem--I couldn't find the file, but I was looking in bin/Debug!

Upvotes: 2

Related Questions