logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ronen Mashal <rmas...@magicsoftware.com>
Subject Re: Two logs have the same appenders
Date Sun, 05 Oct 2014 04:29:09 GMT
Hello Rob,

If you want to write the same messages to two separate files you should do
the following:
1) Define two file appenders in the configuration file, each writing to a
different file.
2) Create a logger (or specify in the "root" logger) that it uses both file
appenders, something like this:
<logger name="a.b.c.classname">
    <appender-ref ref="filelogger1"/>
    <appender-ref ref="filelogger2"/>
</logger>

Now, if you want to direct different messages to different log files, you
would have to define another logger and use that logger in the code. Here's
an example:

<logger name="a.b.c.classname">
     <appender-ref ref="filelogger1"/>
</logger>

<logger name="a.b.c.classname.special">
     <appender-ref ref="filelogger2"/>
</logger>

then in the code:
ILog logger1 = log4net.LogManager.GetLogger(typeof(classname));
ILog logger2 = log4net.LogManager.GetLogger(typeof(classname).FullName +
".sepcial");

Now you'd be able to write different message to different files.

There are other options that involve using filters if you want, for
example, to write all messages to one log but only a subset to another.

Ronen Mashal.


On Fri, Oct 3, 2014 at 11:45 PM, Rob Richardson <RDRichardson@rad-con.com>
wrote:

> I want to get two independent sets of appender objects from the same
> configuration file, so that I can use different file names in a
> FileAppender, for example.  But the standard way of getting appender
> objects is to use the LogManager object, which is static.  Since there's
> only one LogManager, it will always return the same set of appender
> objects.  So, I get one ILog object, get its FileAppender object, set its
> file name, and write a message, and it appears in the expected file.  Then,
> I get another ILog object, get the FileAppender object,  set its file name
> to some other file, and write a message, and that message appears in the
> second file.  Finally, I go back to the first file appender, write another
> message, and it appears in the second appenders file.
>
> Is there a way to copy a FileAppender object, or to get a new object for
> the same appender name out of the LogManager?
>
> Thanks very much!
>
> RobR, who will probably have to just build the logger programmatically
> instead of using a configuration file
>



-- 



[image: email_sig] <http://www.magicsoftware.com/>
*Ronen Mashal*
*Software Engineer *| Magic Software Enterprises Ltd.

Tel. +972-3-5389215       |       Fax. +972-3-5389333
rmashal@magicsoftware.com | www.magicsoftware.com
<http://www.magicsoftware.com/?utm_source=email> | [image: Facebook]
<http://www.facebook.com/MagicSoftwareEnterprises>[image: Twitter]
<http://twitter.com/#%21/MagicSoftware>[image: Linkedin]
<http://www.linkedin.com/e/gis/130018/09F34B270EFF>[image: YouTube]
<http://www.youtube.com/MagicSoftware>[image: Google+]
<https://plus.google.com/108972177316548101047/posts>[image: Magic Software
Blog] <http://blog.magicsoftware.com/>





DISCLAIMER. Information in this message and its attachments may be
privileged or confidential. It is for the exclusive use of the intended
recipient(s).
If you are not one of the intended recipients, you are hereby informed that
any use, disclosure, distribution, and/or copying of this information is
strictly prohibited.
If you receive this message in error, please notify the sender immediately
and delete all copies of this message. We recommend that you scan your
incoming Emails.
We cannot accept responsibility for any transmitted viruses.

Mime
View raw message