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 Leo Mathew <le...@sonata-software.com> on 2010/02/09 08:08:35 UTC
Want to modify my existing log file name to include a dynamic variable value
Hi All,
I want to modify my existing log file name to include a dynamic variable
value.
Below is my log file.
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false">
<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="logs\\intserver" />
<param name="AppendToFile" value="true" />
<param name="StaticLogFileName" value="False" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="'.'yyyy-MM-dd'.txt'" />
<param name="RequestId" value="99" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t]
%-5p %c{1} - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
Based on the above my existing or today's log file name is
intserver.2010-02-09.txt where 2010-02-09is today's date
I have a dynamic variable which I need to set in C#. In case the value
for my dynamic variable is 1000, my log file should be
intserver.2010-02-09.1000.txt
Does any one know how this can be done?
Regards,
Leo
RE: Want to modify my existing log file name to include a dynamic variable value
Posted by Alasdair Richardson <al...@jabcap.com>.
I wanted to do somehting similar, and used the fact that some log4net
parameters can be picked up from environment vars
so in my code I set an env var JCE_LOG_FILE
string logFile = dir + "\\" + AppName + "." + CurrentNTUser;
Environment.SetEnvironmentVariable("JCE_LOG_FILE", logFile);
Then configure log4net
log4net.Config.XmlConfigurator.Configure(new FileInfo(configFile));
and in the config file
<appender name="file" type="log4net.Appender.RollingFileAppender">
<file value="${JCE_LOG_FILE}"/>
<appendToFile value="true"/>
<staticLogFileName value="false"/>
<rollingStyle value="Date"/>
<datePattern value=".yyyy-MM-dd".log""/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{ISO8601} [%thread] %-5level
%logger - %message%newline" />
</layout>
</appender>
Obviously to make this work you need to control yourself when you
configure log4net. Not sure how you would use this to get the actual
pattern you want - eg you would have to check if 'datePattern' can be
picked up from an env var. I tried to use JC_LOG_LEVEL to set the root
logging level and it didnt work ..
Alasdair
________________________________
From: Leo Mathew [mailto:leo.m@sonata-software.com]
Sent: 09 February 2010 08:09
To: Log4NET User
Subject: Want to modify my existing log file name to include a
dynamic variable value
Hi All,
I want to modify my existing log file name to include a dynamic
variable value.
Below is my log file.
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false">
<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="logs\\intserver" />
<param name="AppendToFile" value="true" />
<param name="StaticLogFileName" value="False" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern"
value="'.'yyyy-MM-dd'.txt'" />
<param name="RequestId" value="99" />
<layout
type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d [%t] %-5p %c{1} - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
Based on the above my existing or today's log file name is
intserver.2010-02-09.txt where 2010-02-09is today's date
I have a dynamic variable which I need to set in C#. In case the
value for my dynamic variable is 1000, my log file should be
intserver.2010-02-09.1000.txt
Does any one know how this can be done?
Regards,
Leo
________________________________
The information contained in this transmission
is intended only for the person or entity to
which it is addressed and may contain confid-
ential and/or privileged information. If you
are not the intended recipient (or have received
this e-mail in error) please notify the sender
immediately and delete this e-mail. Any unauth-
orised copying, disclosure or distribution of
the material in this e-mail is strictly forbidden.