log4net 不生成日志原因

前奏:引用dll
 
 
第一步:Program  (不生成日志就有可能是这里的问题
// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
// This will cause log4net to look for a configuration file
// called ConsoleApp.exe.config in the application base
// directory (i.e. the directory containing ConsoleApp.exe)
第二步:具体Form
 // Create a logger for use in this class
        //private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger("MainFrom");
        // NOTE that using System.Reflection.MethodBase.GetCurrentMethod().DeclaringType
        // is equivalent to typeof(LoggingExample) but is more portable
        // i.e. you can copy the code directly into another class without
        // needing to edit the code.
第三步:app.config
 
 <!-- Register a section handler for the log4net section -->
  <configSections>
    <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
  </configSections>
 
<appSettings>
    <!-- To enable internal log4net logging specify the following appSettings key -->
    <add key="log4net.Internal.Debug" value="false"/>
</appSettings>
 
 <!-- This section contains the log4net configuration settings -->
  <log4net>
    <appender name="PatternFileAppender" type="ZXManagerServer.Appender.PatternFileAppender">
      <!-- File pattern to group files by date, then by session property -->
      <file value="log\%date{yyyy-MM-dd}\log.log" />
      <layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
    </appender>
 
    <!-- Setup the root category, add the appenders and set the default level -->
    <root>
      <appender-ref ref="PatternFileAppender" />
    </root>
  </log4net>
 
第四部:
 
Appender 那个文件复制到工程里面
posted on 2014-02-18 08:40  --Sam--  阅读(563)  评论(0编辑  收藏  举报