问题描述
我有一个使用log4net的一个.net 4.0 Windows服务应用程序。
I have a .Net 4.0 windows service application that uses log4net.
下面是我的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>
日志记录工作正常时的服务,而使用建在调试模式下的exe文件(记录在正确的文件路径创建文件)启动,但它使用内置的发布模式的exe文件时,无法正常工作。
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.
我使用的是重新编译log4net的DLL对于.NET 4.0以下,在这个博客中提到的步骤尝试.. http://tseonet.blogspot.com/2010/07/making-log4net-run-on-net-40.html.
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.
但是,这也不能工作。
任何帮助是极大的AP preciated。
Any help is greatly appreciated.
推荐答案
我建议打开内部调试如下解释:
I suggest to turn on internal debugging as explained here:
http://stackoverflow.com/questions/3121975/log4net-appenders-not-working-in-iis7-5/3126675#3126675
这篇关于在运行内置的发行模式下的.Net 4.0的Windows应用程序时的log4net不记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!