我正在使用 log4net 来记录我的项目。我需要在我的应用程序中创建多个日志文件。我能够创建日志文件,但似乎 log4net 无法写入。
请在下面查看我的编码:
public void Execute(IJobExecutionContext context)
{
strLoadFilePath = @"E:\lewre\excel\stock\";
strLoadFileName = @"iCenterProductConcept_*.xls";
strCopyFilePath = @"E:\lewre\excel\stock\Processed\";
strCopyFileName = @"iCenterProductConceptProcess_" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xls";
//--Assign log4net path --
log4net.GlobalContext.Properties["fileName"] = strCopyFilePath + "GeneralLog_" + DateTime.Now.ToString("yyyyMMddHHmm");
//log4net.GlobalContext.Properties["errorFileName"] = strCopyFilePath +"ErrorLog_"+ DateTime.Now.ToString("yyyyMMddHHmm");
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("App.config"));
////**Assign log4net path **
logger.Debug("test");
}
Log4net 配置:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<appSettings>
<add key="log4net.Internal.Debug" value="false" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<!--<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,
 Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
<arg key="configFile" value="E:\\lewre\LewrerpLog\LewreQuartzLog.log" />
<arg key="level" value="ALL" />
</factoryAdapter>
</logging>
</common>-->
<log4net>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%property{fileName}.txt"/>
<appendToFile value="false"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="-1"/>
<maximumFileSize value="1024KB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger - %message%newline"/>
</layout>
<filter type="log4net.Filter.PropertyFilter">
<Key value="Version" />
<StringToMatch value="1" />
</filter>
</appender>
<root>
<level value="All" />
<appender-ref ref="FileAppender" />
</root>
</log4net>