Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OutputDebugStringAppender在Visual Studio中不工作_C#_Visual Studio_Log4net_Mstest - Fatal编程技术网

C# OutputDebugStringAppender在Visual Studio中不工作

C# OutputDebugStringAppender在Visual Studio中不工作,c#,visual-studio,log4net,mstest,C#,Visual Studio,Log4net,Mstest,我遵循了log4net的建议。然后我在VisualStudio2010中点击“F5”启动MsTest单元测试。当单元测试执行这两行时: log.Warn("hello"); //this is a log4net logger. System.Diagnostics.Debug.Write("there"); …Visual Studio输出窗口仅显示单词“there.”为什么“hello”不输出 当我将调试鼠标悬停在“log”变量上时,它会显示: IsDebugEnabled = fals

我遵循了log4net的建议。然后我在VisualStudio2010中点击“F5”启动MsTest单元测试。当单元测试执行这两行时:

log.Warn("hello");  //this is a log4net logger.
System.Diagnostics.Debug.Write("there");
…Visual Studio输出窗口仅显示单词“there.”为什么“hello”不输出

当我将调试鼠标悬停在“log”变量上时,它会显示:

IsDebugEnabled = false
IsErrorEnabled = true
IsFatalEnabled = true
IsInfoEnabled  = false
IsWarnEnabled  = true
由此我得出结论,配置文件被正确读取。我的log4net配置如下所示:

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


当我添加一个额外的FileAppender时,它创建的文件中确实包含“hello”消息。有任何关于VS debug output窗口没有显示“hello”的线索吗?

请尝试使用DebugAppender而不是OutputDebugStringAppender

将以调用
System.Diagnostics.Debug.Write结束,而OutputDebugStringAppender正在调用非托管代码,Visual Studio将不会捕获它(至少在默认情况下不会,甚至只有在调试时才会捕获,这意味着它将不适用于您的案例)


DebugAppender的输出也可以使用链接文章中提到的DebugView捕获,因此我想不出他使用OutputDebugStringAppender的任何原因

啊!!如此接近,但如此遥远!DebugAppender可以工作,是一个完美的解决方案,不过它强制所有日志条目都以记录器的名称作为前缀。我希望在配置中可以在DebugAppender上设置一个属性,告诉它不要这样做。2021年仍然有效。