logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bonio Lopez" <bonio.lo...@gmx.de>
Subject RE: Why each message printed 2 times?
Date Fri, 14 Jul 2006 10:48:47 GMT
Hi Niko, 
----snip---
If you mean that you have 2 separate processes that are both logging the
same data to the same file, then you would expect the same messages to be
logged, both processes are doing the work, you would expect to see the
messages from both.
----snip---

You misunderstand me. I have 2 applications which need to log messages (not
the same messages) into the same init file. So two processes call the same
init code (which I have posted). So there seems to be 2 appenders with the
same initialization. And each of those 2 appenders loggs. Therefore I
suppose each message is logged 2 times. It seems that I have 2 appenders,
getting every message. Am I right? How can I solve that?

I use .NET1.1, log4net 1.2.9, application type: .NET (not asp)


-----Original Message-----
From: Nicko Cadell [mailto:nicko@neoworks.com] 
Sent: Freitag, 14. Juli 2006 11:31
To: Log4NET User
Subject: RE: Why each message printed 2 times?

If you mean that you have 2 separate processes that are both logging the
same data to the same file, then you would expect the same messages to be
logged, both processes are doing the work, you would expect to see the
messages from both.

You might want to configure the layout to include the process id of the
process that is logging so that you can differentiate between your 2
processes.

Setup the process id in the GlobalContext when you initialise logging:

log4net.GlobalContext.Properties["processId"] =
System.Diagnostics.Process.GetCurrentProcess().Id;

Then add "%property{processId}" to your layout pattern.

If this isn't your scenario could you explain a little more your
architecture and the relationship between the appenders and the 2 processes
calling the initialisation code.

> Also standard questions: log4net version, .net runtime version, 
> application type (ASP.NET/EXE)

Answering these might also be helpful.

Cheers,

Nicko

> -----Original Message-----
> From: Bonio Lopez [mailto:bonio.lopez@gmx.de]
> Sent: 14 July 2006 08:13
> To: 'Log4NET User'
> Subject: RE: Why each message printed 2 times?
> 
> Hi Niko,
> I understand now what is going on. The initialization code is called 
> from 2 processes and appender writes in the same file.
> Is it possible somehow to attach to the same appender from other 
> process? Is there some "shared"
> log4net appender object, which can be acquired from other process, 
> when one process already initialized it?
> i.e.
> If XXX.already_initialized then attach else initialize.
> 
> Thank you very much
> 
> -----Original Message-----
> From: Nicko Cadell [mailto:nicko@neoworks.com]
> Sent: Mittwoch, 12. Juli 2006 10:34
> To: Log4NET User
> Subject: RE: Why each message printed 2 times?
> 
> This is usually caused by having 2 appenders writing to the same 
> output.
> These could be both attached to the same logger or to different 
> loggers (i.e. a logger and the root logger).
> 
> Can you post your complete configuration code (looks like you are 
> doing it in code rather than via an xml file). Or a simplified version 
> of your code that demonstrates this (just the config code and a single 
> log call would do). Are you calling your config code only once or 
> multiple times?
> 
> Have you enabled log4net's internal debugging?
> http://logging.apache.org/log4net/release/faq.html#internalDebug
> 
> Also standard questions: log4net version, .net runtime version, 
> application type (ASP.NET/EXE)
> 
> Cheers,
> Nicko
> 
> > -----Original Message-----
> > From: Bonio Lopez [mailto:bonio.lopez@gmx.de]
> > Sent: 11 July 2006 17:51
> > To: 'Log4NET User'
> > Subject: Why each message printed 2 times?
> > 
> > Dear all,
> > With minimal lock each message is printed into a log file 2 times. 
> > i.e.
> > [11 Jul 2006 18:43:10,663] DEBUG Log1  - pi is nothing
> > [11 Jul 2006 18:43:10,663] DEBUG Log1  - pi is nothing With
> exclusive
> > lock works as expected.
> > Any ideas why?
> > 
> > 
> > 
> > m_LockingModel = new FileAppender.MinimalLock();
> m_FileAppender = new
> > FileAppender(); m_FileAppender.Layout = new 
> > log4net.Layout.PatternLayout("[%date{dd MMM yyyy
> HH:mm:ss,fff}] %level
> > %logger  - %message%newline"); m_FileAppender.File = path_to_log + 
> > @"\" + m_logger_file_name; m_FileAppender.LockingModel = 
> > m_LockingModel; m_FileAppender.ImmediateFlush = true; 
> > m_FileAppender.AppendToFile = true;
> > 
> > 
> 
> 


Mime
View raw message