log4net不会写入可视Web开发人员控制台

时间:2011-09-18 08:21:47

标签: console log4net appender

这是我对log4net的配置,但它不会写入控制台
请参阅appender:ConsoleAppender

<?xml version="1.0" encoding="utf-8"?>
<configuration>


  <configSections>
    <section name="log4net"
       type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
      <param name="File" value="C:\Users\name\Documents\visual studio 2010\Projects\logs\logfile.txt" />
      <param name="AppendToFile" value="true" />
      <layout type="log4net.Layout.PatternLayout">

        <param name="ConversionPattern" value="%d [%t] %-5p  %C %m%n%newline" />
      </layout>
    </appender>

    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
      <layout type="log4net.Layout.PatternLayout">

        <param name="ConversionPattern" value="%d [%t] %-5p  %C %m%n%newline" />
      </layout>
    </appender>

    <root>
      <level value="ALL" />
      <appender-ref ref="LogFileAppender" />
      <appender-ref ref="ConsoleAppender" />
    </root>
  </log4net>
</configuration>

为什么不写入控制台?

修改1 这是我初始化它的方式:

log4net.Config.XmlConfigurator.Configure(new FileInfo("C:\\Users\\name\\Documents\\Visual Studio 2010\\Projects\\ExecutionEngine\\Libraries\\App.Config"));

由于

1 个答案:

答案 0 :(得分:6)

您可以使用trace appender来实现此目的。例如:

<appender name="TraceAppender"
          type="log4net.Appender.TraceAppender" >
    <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%-6level - %message%newline" />
    </layout>
</appender>