You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Walden H. Leverich" <Wa...@TechSoftInc.com> on 2007/10/09 15:14:22 UTC

Including PID in log file name -- Locking Models & ASP.Net

Short question: Is there a way in the RollingFileAppender to use the
process ID (PID) in the file name?

 

Long question: 

 

We're using log4net (1.2.10) in several ASP.Net applications. We're also
using the RollingFileAppender rolling daily, and using a static file
name, so the current log-file is "log-file.log" and past log files would
be "log-file.log.2007-08-10.log" for example. 

 

One of the things we've realized is that we need to specify the
FileAppender+MinimalLock locking model in order for this to work. The
reason is, as the ASP.Net worker processes cycle there can be two worker
processes running at the same time, the one that's starting and the one
that's ending. W/out that locking model the new process is unable to get
a lock on the file, because the old process is still running so we miss
logging.

 

What we'd like to is use the PID in the file name of the log file, that
way we know the log file names will be unique and we can get rid of the
FileAppender+MinimalLock locking and increase our logging performance.
So... is there a way in the RollingFileAppender to use the process ID
(PID) in the file name?

 

Ideas?

 

-Walden

 

-- 

Walden H Leverich III
Tech Software
(516) 627-3800 x3051

WaldenL@TechSoftInc.com
http://www.TechSoftInc.com
<BLOCKED::blocked::http://www.techsoftinc.com/> 

Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)


RE: Including PID in log file name -- Locking Models & ASP.Net

Posted by "Walden H. Leverich" <Wa...@TechSoftInc.com>.
<file type="log4net.Util.PatternString">
    <conversionPattern value="C:\Logs\log-%date{
yyyy.MM.dd.HH.mm.ss}-[%processid].log" />
</file>



 

That's the ticket! Thanks. Oddly enough, that has shown me that .net can
tear down an app domain w/out starting a new worker process. I thought a
new app domain (say, changing web.config) always resulted in a new
background process. I hope the locks are held by the process and not by
the domain. J

 

-Walden

 

-- 

Walden H Leverich III
Tech Software
(516) 627-3800 x3051

WaldenL@TechSoftInc.com
http://www.TechSoftInc.com
<BLOCKED::blocked::http://www.techsoftinc.com/> 

Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)

From: Peter Drier [mailto:peter.drier@gmail.com] 
Sent: Tuesday, October 09, 2007 10:31 AM
To: Log4NET User
Subject: Re: Including PID in log file name -- Locking Models & ASP.Net

 

Try this..

<appender name="ErrorLogAppender"
type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString">
        <conversionPattern value="C:\Logs\log-%date{
yyyy.MM.dd.HH.mm.ss}-[%processid].log" />
    </file>
    <threshold value="WARN"/>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %location -
%message%newline" /> 
    </layout>
</appender>

-Peter

On 10/9/07, Walden H. Leverich <WaldenL@techsoftinc.com > wrote:

Short question: Is there a way in the RollingFileAppender to use the
process ID (PID) in the file name?

 

Long question: 

 

We're using log4net (1.2.10) in several ASP.Net applications. We're also
using the RollingFileAppender rolling daily, and using a static file
name, so the current log-file is "log-file.log" and past log files would
be "log-file.log.2007-08-10.log" for example. 

 

One of the things we've realized is that we need to specify the
FileAppender+MinimalLock locking model in order for this to work. The
reason is, as the ASP.Net worker processes cycle there can be two worker
processes running at the same time, the one that's starting and the one
that's ending. W/out that locking model the new process is unable to get
a lock on the file, because the old process is still running so we miss
logging.

 

What we'd like to is use the PID in the file name of the log file, that
way we know the log file names will be unique and we can get rid of the
FileAppender+MinimalLock locking and increase our logging performance.
So... is there a way in the RollingFileAppender to use the process ID
(PID) in the file name?

 

Ideas?

 

-Walden

 

-- 

Walden H Leverich III
Tech Software
(516) 627-3800 x3051

WaldenL@TechSoftInc.com
http://www.TechSoftInc.com

Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)

 


Re: Including PID in log file name -- Locking Models & ASP.Net

Posted by Peter Drier <pe...@gmail.com>.
Try this..

<appender name="ErrorLogAppender" type="log4net.Appender.RollingFileAppender
">
    <file type="log4net.Util.PatternString">
        <conversionPattern
value="C:\Logs\log-%date{yyyy.MM.dd.HH.mm.ss}-[%processid].log"
/>
    </file>
    <threshold value="WARN"/>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %location -
%message%newline" />
    </layout>
</appender>

-Peter

On 10/9/07, Walden H. Leverich <Wa...@techsoftinc.com> wrote:
>
>  Short question: Is there a way in the RollingFileAppender to use the
> process ID (PID) in the file name?
>
>
>
> Long question:
>
>
>
> We're using log4net (1.2.10) in several ASP.Net applications. We're also
> using the RollingFileAppender rolling daily, and using a static file name,
> so the current log-file is "log-file.log" and past log files would be
> "log-file.log.2007-08-10.log" for example.
>
>
>
> One of the things we've realized is that we need to specify the
> FileAppender+MinimalLock locking model in order for this to work. The reason
> is, as the ASP.Net worker processes cycle there can be two worker
> processes running at the same time, the one that's starting and the one
> that's ending. W/out that locking model the new process is unable to get a
> lock on the file, because the old process is still running so we miss
> logging.
>
>
>
> What we'd like to is use the PID in the file name of the log file, that
> way we know the log file names will be unique and we can get rid of the
> FileAppender+MinimalLock locking and increase our logging performance. So…
> is there a way in the RollingFileAppender to use the process ID (PID) in the
> file name?
>
>
>
> Ideas?
>
>
>
> -Walden
>
>
>
> --
>
> Walden H Leverich III
> Tech Software
> (516) 627-3800 x3051
>
> WaldenL@TechSoftInc.com
> http://www.TechSoftInc.com
>
> Quiquid latine dictum sit altum viditur.
> (Whatever is said in Latin seems profound.)
>

RE: Including PID in log file name -- Locking Models & ASP.Net

Posted by Dave McEwan <dm...@harmonyis.com>.
You could simply grab the PID in your .Net code, and then use the
NDC.Push to push it onto the stack.  It will then be available for
logging.

 

pid = GetPID(); <-- you need to write some code to actually get the PID

using(NDC.Push("pid"))
{
    ... all log calls will have your pid included ...
 
} // at the end of the using block the message is automatically removed 

 

 

Dave

 

  _____  

From: Walden H. Leverich [mailto:WaldenL@TechSoftInc.com] 
Sent: Tuesday, October 09, 2007 9:14 AM
To: Log4NET User
Subject: Including PID in log file name -- Locking Models & ASP.Net

 

Short question: Is there a way in the RollingFileAppender to use the
process ID (PID) in the file name?

 

Long question: 

 

We're using log4net (1.2.10) in several ASP.Net applications. We're also
using the RollingFileAppender rolling daily, and using a static file
name, so the current log-file is "log-file.log" and past log files would
be "log-file.log.2007-08-10.log" for example. 

 

One of the things we've realized is that we need to specify the
FileAppender+MinimalLock locking model in order for this to work. The
reason is, as the ASP.Net worker processes cycle there can be two worker
processes running at the same time, the one that's starting and the one
that's ending. W/out that locking model the new process is unable to get
a lock on the file, because the old process is still running so we miss
logging.

 

What we'd like to is use the PID in the file name of the log file, that
way we know the log file names will be unique and we can get rid of the
FileAppender+MinimalLock locking and increase our logging performance.
So... is there a way in the RollingFileAppender to use the process ID
(PID) in the file name?

 

Ideas?

 

-Walden

 

-- 

Walden H Leverich III
Tech Software
(516) 627-3800 x3051

WaldenL@TechSoftInc.com
http://www.TechSoftInc.com
<BLOCKED::blocked::http://www.techsoftinc.com/> 

Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)