VS 2010 log4net MSTest MSUnit 未记录到控制台(但记录到文件正常)

发布于 2024-12-23 01:43:16 字数 1881 浏览 1 评论 0原文

这最终归结为一个简单的问题:为什么 Console.WriteLine("asdfasdf") 无法将输出输出到 Visual Studio 2010 中的输出窗口???因为我的在运行测试时没有在那里输出。

我有一个日志配置文件,当我在调试模式下运行程序时,它会记录到文件并记录到 VS 输出窗口。当我将它与 MS Test 一起使用时,该文件会记录到我指定的文件,该文件最终为 TestResults/xxxx/example.log 但不会记录到 VS 输出窗格。这是为什么?这是非常非常烦人的,因为我喜欢使用输出来滚动日志。

我在 log4net 中的配置在一个而不是另一个中工作

 <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>

我在我的测试用例中调用它

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

我在我的程序中调用它因为它实际上被移动到 bin\Debug\conf 目录中....

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

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

这对我来说绝对没有意义为什么这行不通?
谢谢, 院长

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷清清 2024-12-30 01:43:16

我不认为输出窗格实际上反映了控制台输出。相反,在“测试结果”窗格中,右键单击测试问题并从上下文菜单中选择“查看测试结果详细信息”。每个测试的结果详细信息包含该测试的控制台输出。

另外,谢谢,我遇到了相反的问题——我找不到该文件,但我正在 bin/Debug 中查找!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文