我正在使用管理员用户在Windows XP上使用C#开发.NET Framework 3.5,使用log4net作为.NET Framework 2.0二进制引用。我尝试过What am I missing with log4net - No log file created但对我无效。我将以下内容添加到AssemblyInfo.cs中:
我创建了一个名为“Log4Net.config”的文件,如下所示。然而,当我运行控制台应用程序时,在我的项目中找不到任何日志文件。我错过了什么?
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]
我创建了一个名为“Log4Net.config”的文件,如下所示。然而,当我运行控制台应用程序时,在我的项目中找不到任何日志文件。我错过了什么?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<!--
log4net documentation http://logging.apache.org/log4net/
Logging levels in order of increasing priority:
* ALL
* DEBUG
* INFO
* WARN
* ERROR
* FATAL
* OFF
-->
<appender name="DebugLog" type="log4net.Appender.FileAppender">
<file value="MyLog_debug.log" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<maximumFileSize value="5MB" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="DEBUG" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="InfoLog" type="log4net.Appender.RollingFileAppender">
<file value="MyLog_info.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<maxSizeRollBackups value="7" />
<maximumFileSize value="5MB" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="WARN" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="ErrorLog" type="log4net.Appender.RollingFileAppender">
<file value="MyLog_error.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<maxSizeRollBackups value="30" />
<maximumFileSize value="5MB" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date %-5level %logger - %message%newline" />
</layout>
</appender>
<!-- Set the default logging level and add the active appenders -->
<root>
<level value="ALL" />
<appender-ref ref="DebugLog" />
<appender-ref ref="InfoLog" />
<appender-ref ref="ErrorLog" />
</root>
</log4net>
</configuration>