Hi I’m trying to set up log4net without using XML configuration:
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);
}
My problem is that I want to use two appenders (smtp and file). Using
BasicConfigurator.Configure(smtpAppender);
I can set the initial one but I also need to set the file appender. Do you know a why to do it?
Thanks for your time 🙂
In this scenario, you want to get the instance of the logger then add your appenders. After that, just configure the repository. I.e. ,
In VB:
In C#: