這是我第一次使用Log4net
。它不顯示任何錯誤,但不寫入文件。我添加下面我AppConfig
文件:Log4net for windows服務
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%5level [%thread] (%file:%line) - %message%newline"/>
</layout>
</appender>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\CE\FileControllerLog.txt"/>
<layout type="log4net.Layout.PatternLayout">
<!--<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>-->
<param name="ConversionPattern" value="%d %m%n"/>
</layout>
<appendToFile value="true"/>
<rollingStyle value="Composite"/>
<maxSizeRollBackups value="2"/>
<maximumFileSize value="10MB"/>
<staticLogFileName value="true"/>
</appender>
<logger name="FileControllerLog">
<level value="INFO"/>
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ConsoleAppender"/>
</logger>
[assembly: log4net.Config.XmlConfigurator(Watch = true)] //added in assembly info file
和代碼:
ILog logger = log4net.LogManager.GetLogger("FileControllerLog");
logger.Info("Method starts");
它不記錄。
嘗試在常規控制檯應用程序代碼和配置,看看它的工作原理。 –