log4net doesnt work when project is set to Release build
When I build my project in Debug mode log4net works, so the log file is created and written to as expected. However, when I build my project in Release mode, and copy files to production server, log4net does not create the log file or write to it.
If I copy files using Debug mode log4net works in production server.
I enabled internal debugging. When running in Release mode the internal log files shows:
log4net: Assembly [WebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
webconfig file:
<log4net debug="true">
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="webapi.log" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="2" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="appTrace.txt" />
</listeners>
</trace>
</system.diagnostics>
How do I get log4net working when building in Release mode?
尝试在WebAPI项目中将[assembly:RepositoryAttribute(“Your.Namespace.Here”)]添加到AssemblyInfo.cs中。
链接地址: http://www.djcxy.com/p/43660.html