//下面是用来创建滚动文件appender
if (!this.mConfigured)
{
// Create the appender
IAppender appender = this.CreateRollingFileAppender(pNewTraceConfiguration);
// Add the appender to the root logger
Logger rootLogger = this.mRepository.Root;
if (rootLogger != null)
{
rootLogger.AddAppender(appender);
}
this.mRepository.Configured = true;
this.mRepository.RaiseConfigurationChanged(new EventArgs());
}
private IAppender CreateRollingFileAppender(TraceConfigurationClass pTraceConfiguration)
{
// Location of the trace file
string traceFileDir = pTraceConfiguration.OutputDirectory;
if (string.IsNullOrWhiteSpace(traceFileDir))
{
// if the location is not suppliied, take the application directory
traceFileDir = this.DefaultTraceDirecotry;
}
// Prefix of the trace filename
string traceFilePrefix = pTraceConfiguration.FilenamePrefix;
if (string.IsNullOrWhiteSpace(traceFilePrefix))
{
// if the prefix is not suppliied, take the default one
traceFilePrefix = DEFAULT_TRACE_FILENAME_PREFIX;
}
traceFilePrefix += "_" + logPrefix;
// Size of the trace file
int traceFileSize = pTraceConfiguration.MaxFileSizeKB;
if (traceFileSize <= 0)
{
traceFileSize = DEFAULT_TRACE_FILESIZE_KB;
}
// Creation of the appender
string filename = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}-[{2,5}]_{3}.log",
traceFileDir,
traceFilePrefix,
ProcessID,
DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss", CultureInfo.InvariantCulture));
Debug.WriteLine("AlsF_Log4netLogger: creating log file [" + filename + "] with file size [" + traceFileSize.ToString() + "]KB");
RollingFileAppender appender = new RollingFileAppender()
{
Name = "RollingFile",
// example fo filename : <dir>\NewIHM-[ PID]_yyyy_MM_dd_HH_mm_ss.log
File = filename,
AppendToFile = false,
RollingStyle = RollingFileAppender.RollingMode.Size,
MaximumFileSize = traceFileSize.ToString() + "KB",
CountDirection = 1,
MaxSizeRollBackups = -1
};
// Layout for the appender : message, header and footer
PatternLayout layout = new PatternLayout()
{
ConversionPattern = MESSAGE_PATTERN,
Header = HEADER_PATTERN,
Footer = FOOTER_PATTERN
};
layout.ActivateOptions();
appender.Layout = layout;
appender.ActivateOptions();
return appender;
}
现在基于 Exe 不同的配置文件路径被用于创建日志文件,但问题是因为正在生成 3 个运行 3 个文件的 exe,并且 exe1 数据被记录在所有 3 个文件中,这不是预期的。
根据 exe 特定的 exe 数据应该只转到特定的日志文件。请帮帮我。在此先感谢您的帮助。