If you have a PH account, you can customize your PH profile.

VB.NET

Moderators: seancampbell
Number of threads: 3653
Number of posts: 9344

This Forum Only
Post New Thread

Report
Filename in log4net Posted by dnsl on 25 Nov 2009 at 4:43 AM

Hi All,
i am doing a VB.NET windows application. In that i am using Log4Net for logging details. I am new to using Log4Net. The problem i am facing is i want to create the logfiles with same name each day. means today if a log file is created with name debug.log, tomorrow also it should create a new log file with same name with out any change in the previous file name. how can i do this ? My appender configuration looks like this ..

<appender name="RSLogFileAppenderDebug" type="log4net.Appender.RollingFileAppender">
<file value="C:\Log4NetExamples\debug.log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<filter type="log4net.Filter.LevelRangeFilter">
<acceptOnMatch value="true" />
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
<maxSizeRollBackups value="1" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level - %message" />
</layout>
</appender>

<appender name="RSLogFileAppenderFatal" type="log4net.Appender.RollingFileAppender">
<file value="C:\Log4NetExamples\Fatal.log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<filter type="log4net.Filter.LevelRangeFilter">
<acceptOnMatch value="true" />
<levelMin value="FATAL" />
<levelMax value="FATAL" />
</filter>
<maxSizeRollBackups value="1" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level - %message" />
</layout>
</appender>

<root>
<level value="ALL" />
<appender-ref ref="RSLogFileAppenderDebug" />
<appender-ref ref="RSLogFileAppenderFatal" />
</root>

How can i do this ?? do i need to make any change in the appender config ? can anybody help?
Report
Re: Filename in log4net Posted by seancampbell on 1 Dec 2009 at 8:41 AM
I don't know anything about the software you are using... I did how ever read a few things just now and here is a suggestion (don't know if this will help or not)...

Based on what I read (here: http://logging.apache.org/log4net/release/config-examples.html) you should be able to specify Environment Variables in the filename of the Log File... There is NO WAY to have 2 files with the SAME NAME in the SAME LOCATION, so if you want to have a new file each day, you have to create a file with a new name... Based on what I read on Logging.apache.org, you should be able to specify a dynamic filename, but how this acts I couldn't tell you since I have never used this before...

here goes:
'First you want to set the Enviroment Variable when you load your software
System.Environment.SetEnvironmentVariable("log4netFile", "log-" & Format(Now.ToString, "MM-dd-yyyy") & ".txt")

Now that your environment var is set, you can use that $(log4netFile) environment variable in the FileName of the log4net settings in app.config.

Hope this atleast gets you moving down a path towards solving your question



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A BootstrapLabs project.