Log4net无法写入事件日志,只创建该文件

时间:2012-05-24 10:50:20

标签: windows log4net

在本地计算机上,log4net写入事件日志,在服务器上它只创建文件,但不写入文件。
它不能是权限,因为它会创建文件...

有什么建议吗?

<configSections>
   <section name="log4net" type="log4net.Config.Log4NetConfigurationS``ectionHandler,log4net"/>
   <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord"/>
</configSections>


<log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="C:\Logs\Services"/>
            <appendToFile value="true"/>
            <staticLogFileName value="false"/>
            <rollingStyle value="Composite"/>
            <datePattern value="yyyyMMdd.lo\g"/>
            <maxSizeRollBackups value="5"/>
            <maximumFileSize value="100MB"/>
            <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%newline %date [%thread] %-5level %logger - %message%newline"/>
           </layout>
    </appender>
    <root>
          <!-- priority value can be set to ALL|INFO|WARN|ERROR -->
      <level value="ALL"/>
      <appender-ref ref="RollingLogFileAppender"/>
      </root>
</log4net>

编辑:我可以给你的更多信息

在LOG4NET的DEBUG MODE上,它写在服务器上,我可以看到所有的DEBUG LOG

并完成这些行

log4net: Type = [3], r0 = [19700101.log], r1 = [19700102.log]  
log4net: curSizeRollBackups starts at [0]  
log4net: reated Appender [RollingLogFileAppender]  
log4net: Adding appender named [RollingLogFileAppender] to logger [root]  
log4net: Hierarchy Threshold []  
log4net: Shutdown called on Hierarchy [log4net-default-repository]

1 个答案:

答案 0 :(得分:1)

除非您发布了错误的配置,否则您没有任何EventLogAppender。

尝试添加:

<log4net>
 <appender name="eventlog" type="log4net.Appender.EventLogAppender">
  <param name="ApplicationName" value="yourappname" />
  <param name="LogName" value="yourlognameoneventlog" />
  <param name="Threshold" value="all" />
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%m%n" />
  </layout>
 </appender>

 <root>
      <!-- priority value can be set to ALL|INFO|WARN|ERROR -->
  <level value="ALL"/>
  <appender-ref ref="RollingLogFileAppender"/>
  <appender-ref ref="eventlog" />
 </root>
</log4net>

并根据您的需要更改“ApplicationName”和“LogName”值。