Hi all,
Until now, I used the following code for my log:
Namespace Test
{
Class Class1
{
Private static string appPath = "";
private static ILog log = LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );
private static log4net.Appender.RollingFileAppender
rollingFileAppender;
void Initialize()
{
appPath = Assembly.GetExecutingAssembly().Location;
appPath = appPath.Substring(0, appPath.LastIndexOf(@"\"));
rollingFileAppender = new
log4net.Appender.RollingFileAppender();
rollingFileAppender.File =
String.Format(@"{0}\log\test", appPath);
rollingFileAppender.AppendToFile = true;
rollingFileAppender.DatePattern = "-yyMMdd'.log'";
rollingFileAppender.RollingStyle =
log4net.Appender.RollingFileAppender.RollingMode.Date;
rollingFileAppender.StaticLogFileName = false;
rollingFileAppender.Layout = new
log4net.Layout.PatternLayout("%d{HH:mm:ss} %5p - %m%n");
rollingFileAppender.Encoding =
System.Text.Encoding.UTF8;
rollingFileAppender.Threshold =
log4net.Core.Level.Info;
rollingFileAppender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(
rollingFileAppender );
}
void DebugLog( ref ILog log, string s )
{
if( log != null && s.Length > 0 ) log.Debug( s );
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Initialize();
DebugLog( ref log, "Starting the application..." );
}
}
}
It works well with one log file, but I need to log into two different log
files.
For example:
DebugLog( ref log1, "a message into the log file 1." );
DebugLog( ref log2, "a message into the log file 2." );
Log1 -> log1.log
Log2 -> log2.log
How could I do that with log4net?
I tried with two appenders, but each message is written into the two log
files which I don't want. I want the message1 (resp. message2) to be written
into the log file 1 (resp. log file 2).
Thanks,
Damien