您好我正在尝试在不使用 XML 配置的情况下设置 log4net:
public void InitLogger()
{
//Create exception log file if it haven't been created
var exceptionLogFile = new FileInfo(System.Configuration.ConfigurationManager.AppSettings["ExceptionLogFilePath"]);
if (!exceptionLogFile.Exists)
{
exceptionLogFile.Create();
}
//configure log4net
var smtpAppender = new SmtpAppender
{
SmtpHost = "",
Authentication = SmtpAppender.SmtpAuthentication.None,
BufferSize = 512,
From = "",
To = "",
Layout = new PatternLayout(""),
Lossy = true,
Evaluator = new LevelEvaluator(Level.Error)
};
var fileAppender = new FileAppender
{
File = System.Configuration.ConfigurationManager.AppSettings["ExceptionLogFilePath"],
AppendToFile = true,
Layout = new PatternLayout(""),
LockingModel = new FileAppender.MinimalLock() //use the minimal locking model that allows multiple processes to write to the same file
};
BasicConfigurator.Configure(smtpAppender);
}
我的问题是我想使用两个附加程序(smtp 和文件)。使用
BasicConfigurator.Configure(smtpAppender);
我可以设置初始值,但我还需要设置文件附加程序。你知道为什么要这样做吗?
谢谢你的时间 :)