Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

log4net doesn't log when running a .Net 4.0 Windows application built in Release mode

I have a .Net 4.0 windows service application that uses log4net.

Here's my log4net config.

<log4net>
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{Context}] - %message%newline" />
    </layout>
  </appender>

  <appender name="ColorConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
    <mapping>
      <level value="ERROR" />
      <foreColor value="Red, HighIntensity" />
    </mapping>
    <mapping>
      <level value="FATAL" />
      <foreColor value="Red, HighIntensity" />
    </mapping>
    <mapping>
      <level value="WARN" />
      <foreColor value="Blue, HighIntensity" />
    </mapping>
    <mapping>
      <level value="INFO" />
      <forecolor value="White, HighIntensity" />
    </mapping>
    <mapping>
      <level value="DEBUG" />
      <forecolor value="Green, HighIntensity" />
    </mapping>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{Context}] - %message%newline" />
    </layout>
  </appender>

  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <appendToFile value="true" />
    <datePattern value="yyyyMMdd" />
    <file value="Logs/Server.log" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{Context}] - %message%newline" />
    </layout>
    <maximumFileSize value="10MB" />
    <rollingStyle value="Composite" />
    <staticLogFileName value="true" />
  </appender>

  <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{Context}] - %message%newline" />
    </layout>
  </appender>

  <root>
    <level value="ALL" />
    <appender-ref ref="ColorConsoleAppender" />
    <appender-ref ref="RollingFileAppender" />
  </root>

</log4net>

Logging works as expected when the service starts up while using the exe that was built in debug mode (log files are created at the right file path), but doesn't work when it is using the exe built in release mode.

I've tried using a recompiled log4net dll for .Net 4.0 following the steps mentioned at this blog.. http://tseonet.blogspot.com/2010/07/making-log4net-run-on-net-40.html.

But, that didn't work either.

Any help is greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I suggest to turn on internal debugging as explained here:

log4net - Appenders not working in IIS7.5


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...