1
我正在創建不同的報告並嘗試傳遞報告名稱並將其附加到log4net報告的名稱。每次報告運行時,報告名稱都會有所不同,因此會被動態分配。
我試過使用LOG4NET.GLOBALCONTEXT.PROPERTIES("RptName") = sReportName"
,但我得到的只是報告標題中的「空」值。將動態值傳遞給appender
class Program
{
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
log4net.GlobalContext.**Properties("RptName")** = sReportName
log.Info("this is an info message");
Console.ReadLine();
}
}
<!--RollingFileAppender: Provides output of all log entries to a file in the \logs directory
Filename: RSGetReport_yyyyMMdd_hh:mm:ss_processID.txt-->
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="logs\RSGetReport_%date{yyyyMMdd}_%date{hhmmss}_%processid**_%property{myContext}.**txt" />
<appendToFile value="true" />
<rollingStyle value="Once" />
<maxSizeRollBackups value="10" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ALL" />
</filter>
<maximumFileSize value="1MB" />
<countDirection value="1" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>strong text