logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "dh" ...@cube.org>
Subject RE: Multiple logs?
Date Mon, 02 Jan 2006 09:29:58 GMT

Thank you very much, it works perfectly!

I'm far from using all the capabilities of log4net for now... :)


Better wishes for 2006,

Damien.


-----Message d'origine-----
De : Matthew Brown [mailto:octavius@gmail.com] 
Envoyé : vendredi 30 décembre 2005 16:59
À : dh@cube.org
Objet : Re: Multiple logs?

This should help:
http://logging.apache.org/log4net/release/manual/configuration.html

The settled-upon best practice is that each class gets it's own
logger, and then you can configure the settings in each logger in the
hierarchy however you like in your config file.


On 12/30/05, dh <dh@cube.org> wrote:
> Hi,
>
>   Class1 is just an example, but in the real source code, this is the main
> class of my windows forms application, then it is just a class which has a
> logger.
>
>   I'm going to search in the documentation for a configuration file like
you
> said.
>
> Thanks.
>
>
> -----Message d'origine-----
> De: Matthew Brown [mailto:octavius@gmail.com]
> Envoyé: vendredi 30 décembre 2005 16:27
> À: Log4NET User
> Objet: Re: Multiple logs?
>
> Is Class1 a logger or a class that happens to have a logger?
>
> Either way, you're going to want to create different appenders for the
> different log files.
>
> Have you looked into using a config file to handle configuration? Much
> easier.
>
> On 12/30/05, dh <dh@cube.org> wrote:
> > 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
> >
> >
> >
>
>


Mime
View raw message