Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: how to log to differnent textfiles?
Prev Next
You are not authorized to post a reply.

Author Messages
Drinck@gmx.de

05/19/2008 1:23 PM  

Hello!

I'm quite new in using log4net. :-)
And perhaps you have a quick and easy solution for my problem.

I have an windows application which can be started more than once.
Inside the config file I can set the logfile and path.
But when I start my application more than once, I receive a "file in
use" exception.

Is it possible to set the logfile path at runtime?

Thank you for your help.

best regards,
Mad

Chris Jerdonek

05/19/2008 1:31 PM  

> But when I start my application more than once, I receive a "file in
use" exception.  Is it possible to set the logfile path at runtime?

You can also try using a "minimal lock," which lets multiple processes
write to the same file.  Just add the following to your appender config:

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

This is covered in the log4net config examples in the FileAppender
section:

http://logging.apache.org/log4net/release/config-examples.html

--Chris

--
Chris Jerdonek
Software Developer
P: (415) 357-3618 Ext. 1357
Granicus, Inc.

Drinck@gmx.de

05/19/2008 1:40 PM  


is it possible to combine this with a RollingFileAppender?

best regards,
Mad

Chris Jerdonek

05/19/2008 1:46 PM  

> is it possible to combine this with a RollingFileAppender?

Yes.  This is because "LockingModel" is a property of the FileAppender
class, and the RollingFileAppender class extends FileAppender.  You can
see this for yourself if you go to the log4net SDK reference and click
on log4net.Appender -> RollingFileAppender Class.  The SDK reference is
available here:

http://logging.apache.org/log4net/release/sdk/index.html

It's also available by clicking on "SDK Reference" in the left column of
the main log4net web site.

--Chris


--
Chris Jerdonek
Software Developer
P: (415) 357-3618 Ext. 1357
Granicus, Inc.

Drinck@gmx.de

05/19/2008 1:53 PM  

Hello!

Thanks for reply!

Yes, it works. But when I log many entries in both processes I receive a
log4net:ERROR [RollingFileAppender] Unable to acquire lock on file
and after that an INTERNAL ERROR. Append is False but OutputFile ...
already exists.

There is no way to set the logfile path manual?
Or can I specify the folder to user data folder?

best regards,
Mad

Peter Drier

05/19/2008 4:46 PM  
Hi,

You can use environment variables and a few pre defined ones in the conversion pattern for the filename..  e.g.

        <appender name="DefaultAppender" type="log4net.Appender.RollingFileAppender">
            <file type="log4net.Util.PatternString">
                <conversionPattern value="C:\Logs\Application-%date{yyyy.MM.dd.HH.mm.ss}-[%processid].log" />
            </file>
            <threshold value="ALL"/>
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maximumFileSize value="50MB" />
            <maxSizeRollBackups value="5" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%15.15thread] %-5level %logger{2} - %message%newline" />
            </layout>
        </appender>

-Peter
Ron Grabowski

05/19/2008 11:51 PM  

I wouldn't recommend using the RollingFileAppender with the MinimalLock. There's no way for one instance of the program to know that another instance has rolled the file. The MinimalLock is slow compared to an ExclusiveLock. The most effecient file based appender across multiple processes would probably be a normal FileAppender with a mutext based lock so the processes can coordinate who is writing to the file. Someone has already implemented such a class:

 http://www.mail-archive.com/log4net-user@logging.apache.org/msg04116.html

That would be a good locking model to support in the next release.

Drinck@gmx.de

05/20/2008 10:18 AM  

Hello!

Thanks for the code example.
Can you please give me a hint where I should put this peace of code
inside the log4net solution?

thank you.

Drinck@gmx.de

05/20/2008 10:43 AM  

Hello!

I made it.
Simple add the code to inside #region Locking Models
and activate the new locking with
<lockingModel type="log4net.Appender.FileAppender+MutexLock" />

Works great! :-)

Thank you very much!

Ron Grabowski

05/20/2008 1:50 PM  

You can also place it in another assembly:

 <lockingModel type="Company.Logging.MutexLock, Company.Logging" />

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > how to log to differnent textfiles?



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement