2010-05-08 218 views
1

作爲一個log4net newb/boob我只是從一個NHibernate示例項目中複製行,我可以看到log.txt文件已更新。有沒有一個快速的答案,爲什麼我不創建文件?log4net:我做錯了什麼?

乾杯,
Berryl

[assembly: log4net.Config.XmlConfigurator(Watch = true)] 

我在這裏看到另一篇文章說,這應該在集信息去,但在示例項目,這是一個靜態輔助類只是另一條線。

private static readonly log4net.ILog _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 

而在app.config中,我有

<configSections> 
    <section 
     name="log4net" 
     type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" 
    /> 
</configSections> 

    <!-- This section contains the log4net configuration settings --> 
<log4net> 
    <!-- Define an output appender (where the logs can go) --> 
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net"> 
     <param name="File" value="log.txt" /> 
     <param name="AppendToFile" value="false" /> 
     <layout type="log4net.Layout.PatternLayout, log4net"> 
      <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" /> 
     </layout> 
    </appender> 
    <appender name="LogDebugAppender" type="log4net.Appender.DebugAppender, log4net"> 
     <layout type="log4net.Layout.PatternLayout, log4net"> 
      <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/> 
     </layout> 
    </appender> 

    <!-- Setup the root category, set the default priority level and add the appender(s) (where the logs will go) --> 
    <root> 
     <priority value="ALL" /> 
     <appender-ref ref="LogFileAppender" /> 
     <appender-ref ref="LogDebugAppender"/> 
    </root> 

    <!-- Specify the level for some specific namespaces --> 
    <!-- Level can be : ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF --> 
    <logger name="NHibernate"> 
     <level value="ALL" /> 
    </logger> 
</log4net> 
:不想集信息「惹」我還與以下實際登錄相同的靜態輔助類把它放進一個靜態輔助,沿

回答

1

你正在做正確的事情。

啓用此設置:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <appSettings> 
     <add key="log4net.Internal.Debug" value="true"/> 
    </appSettings> 
</configuration> 

這裏貼上輸出結果。

+0

哇,時間扭曲!遲到比從來沒有更好: - ) – Berryl 2013-01-07 21:44:17

+0

只是想我會寫出來,因爲當人們對着同一堵牆跑頭時, ) – 2013-01-08 10:36:31