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 Richard Fouts <rf...@we-are-it.com> on 2009/06/05 17:01:18 UTC

How do I use dynamic boolean values on RollingFileAppender

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") =
_MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-




Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
Far too true.  Thanks for your assistance again.

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Monday, June 08, 2009 8:40 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

Hi Richard,
 
glad to have been of assistance, if only in so far as being able to
stimulate design :).
 
Thank god you have access to the source!




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 08:28:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

Karim,

 

Please don't misinterpret my abrasiveness as ignorance or aggression.
It is merely there to help spur on some insightful conversation.

 

I better understand your point of view on .config files.  And really you
are absolutely correct, a configuration file should hold the static
configuration of the .NET application/assembly.  However, according to
the log4net documentation, the use of a configuration allows for dynamic
and monitored changes to occur; for example, during runtime the log file
is renamed or relocated by the application.  The XML file which contains
the log4net configuration is modified.  This change is then recognized
by the log4net assembly and the appropriate changes are made dynamically
and on the fly.  As far as the registry is concerned, it's not out of
the question, but I was hoping to stay out of it.  Still though, using
the registry might have merit.  I still though have to deal with how to
allow log4net to pick up the values.  No the registry wouldn't solve the
problem, it would become another mechanism for storing what I am already
storing within the application metadata.  The root problem is the
limited functionality within the log4net assembly with regards to
dynamically assigned variables/settings of non-string types.

 

Usually that is how I approach log management as well, just throw it
into a specific location that is only checked by analysts or engineers.
But this application is a synchronization application.  I need to give
the user the ability to not only check that their synchronization of
data is occurring, but also allow them to specify various attributes of
the logging process.  How long to do they want to keep their log files
for, how many log files do they want to maintain, where do they want to
store their log files at and what do they want their log files named?
[Just to name a few].

 

As for the flexibility, I tend to disagree.  I don't look at this as a
customized non-reusable method, I actually perceive this as a method
that could be used in later development.  Designed the right way, any
method can be ported into any other assembly, this is the beauty of OOP.
But as stated, it has to be designed the right way.  In order to reuse a
class/object, the class/object components have to live and breathe
within the class/object, only instances or reflections of the
class/object exist when in use by your application but never the actual
class/object.

 

Yeah I was just thinking out loud when I stated the XML thought process.
It again gets me another method of storing values, again the problem is
not the storage of the values, it is the limited functionality within
the log4net assembly with regards to dynamically assigned
variables/settings of  non-string types.  But I think, overall, you are
correct, the only correct answer in this case may be to alter the
log4net assembly to add the functionality that I am requiring.

 

Thanks again for your insights.

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Monday, June 08, 2009 7:55 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

Hi Richard,
 
please, dont think i am telling you that you are wrong - I am not. Its
just that I wouldnt have tried to do what you are doing with a .config
file is all.
 
I have always viewed .config files in .Net as files that hold
configuration. If I find that I need to change something on a regular
basis in the .config file, then I tend to turn it into a setting. I
guess in your situation, you could create the logfile itself
programtically based on a value in the .config file, which is the way I
have always veiwed these files should be used for. I think you could
also store the values you need in the registry should you want to.
 
When it comes to log management, I know where my logs are stored and how
they are named based on the application that is creating them, if I have
a deployment app I know exactly where to look to view the logfile for
that app, if I dont, then I can check the config to see where it is
pointing to (or where ever else the value may be). If it is generated in
the code then it would be a bit of a problem for someone who didnt know
where to look in the first place for it.
 
When it comes to flexibility, as soon as you start to control the
configuration of log4net in the code, then you loose the ability to
reuse your code in other apps that could need logging. For instance, I
have a logging library that I can use over and over again in different
projects. All I need to do is reference it in my code and apply the
relevant configuration in the web or app.config - but again, thats just
how I work and how I have seen the way log4net behaves. I do control
some of the config in the code with this lib, but this is because it
logs to a db and not to a file. So I set the connection string this way
(which I read from a config file).
 
However, in saying this, I can start to understand how you are thinking
about this. Most of the logging that I carry out isnt ever really
exposed to a user, its just there to give analysts and techs information
on whats going on (especially when its bad). I dont really need an end
user to control the formatting or location of the log itself etc, the
apps and services that use it just chug away in the background with
everyone oblivious to it.
 
In my previous email, I mentioned that you could create the settings as
an XML file in the code and have the .config read this information. But
you hit a problem here in so far that the .config will be read prior to
the XML being generated. But, you can work around this, as long as the
XML is generated to the same location each time, you can simply reload
the .config for the app picking up the config you just created. i think
the only thing I dont like about that is that you could just put the
config in the .config file from the get go.
 
Like I said before, I dont think at all that you are wrong, I was just
putting my views across. One other soloution would be to alter how
log4net works to give you the behaviour you want, I did something
similar myself to change the way db connections are used (I needed to
attach an analysis tool).




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 07:35:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

You mention in the best spirit of .Net, could you provide a little more
clarification?  I tend to feel that an assembly, log4net.dll in this
example, should be a black box, and how you interact with this black
box, should not affect the underlying codes buildability or stability.
The mere fact that you can use a separate configuration file for the
log4net assembly attests to this ability.  There are also others around
the internet who would tend to agree with my use of an external
configuration file.

 

You also mention the loss of flexibility, please expand upon this.  To
give a better understanding, using an application, how do you know where
the log files are stored and what they are named?  An application such
as Exchange or SQL will show you where the log files are (so far as you
know where to look inside the application interface), and not only that,
will allow for the end user to control some of the basic settings of the
log file [where it is stored, what it is named, will it be a rolling log
file (circular logging), etc. etc.].  If I am unable to use a
configuration file (regardless of app.config or log4net.config) to set
these values then my only recourse will be to programmatically control
the appender.  What are some pro's and con's you can think of?  What
functionality will I lose or gain?

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

I am not saying that the config file doesnt work, I was just suggesting
that the way you are trying to use the file may not be in the best
spirit of .Net.

You can control the configuration of log4net programatically, but you
will loose some of the flexibility that you need (going by the code and
config you mailed earlier). I have installatations that use this type of
appender, but I am happy enough specifiying the name of the logfile in
the config file itself, but again I can fully understand wanting to have
this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea.
.Net will lock the apps .config file though during execution, so you
would need to generate a .config to a seperate location and have the
app.config look this up etc. Once the xml has been generated, you would
need to reload the app.config (or web.config, whichever you are using).
This would then pick up the xml you have just generated.
 
How does that sound?




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org;
log4net-dev@logging.apache.org

As I stated in my post, it is not that the config file does not work, it
does, the main problem is that the %property method does not seem to
have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase
the method that sets the property in the
log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These
properties need to be set before the GetLogger method is called.  As
long as the properties are set before the GetLogger method (hence my two
sub calls to primeLogging [which fills the application variables with
data from either the My.Settings metabase or user entered data] and
configLog4Net [which uses the aforementioned
log4net.GlobalContext.Properties method to set the property values in
the Log4Net instance].  After the properties are set, the GetLogger
method fires and all of the properties are read and the Appenders are
generated.

 

All of my appenders work when I strip out all of the %properties that
are non string based.  Which means that I can set the log path and the
log filename dynamically but the boolean and int64 values will fail
because log4net does not cast these properties as anything other than
string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 
One thing you did mention was possibly creating the xml file within the
application, this is feasible (so long as log4net does not put a file
lock on the config file).  Another method I have been tinkering with
(would rather not use this method, but will if must) is to generate the
appender directly in the application by using the various getters and
setters for the RollingFileAppender.
 
Thanks for you input.

 

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being
generated by log4net? If they are, I dont think you are going to
succeed, the logfile needs to be created prior to logging commencing.
The properties you seem to be supplying wont exist at the point the you
are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not
simply create a file in the code if you really need to do this? I can
understand why you would want to dynamically name a log file, but the
way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") =
_MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/>  

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

Upgrade to Internet Explorer 8 Optimised for MSN. Download Now
<http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U> 

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 




Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
Far too true.  Thanks for your assistance again.

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Monday, June 08, 2009 8:40 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

Hi Richard,
 
glad to have been of assistance, if only in so far as being able to
stimulate design :).
 
Thank god you have access to the source!




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 08:28:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

Karim,

 

Please don't misinterpret my abrasiveness as ignorance or aggression.
It is merely there to help spur on some insightful conversation.

 

I better understand your point of view on .config files.  And really you
are absolutely correct, a configuration file should hold the static
configuration of the .NET application/assembly.  However, according to
the log4net documentation, the use of a configuration allows for dynamic
and monitored changes to occur; for example, during runtime the log file
is renamed or relocated by the application.  The XML file which contains
the log4net configuration is modified.  This change is then recognized
by the log4net assembly and the appropriate changes are made dynamically
and on the fly.  As far as the registry is concerned, it's not out of
the question, but I was hoping to stay out of it.  Still though, using
the registry might have merit.  I still though have to deal with how to
allow log4net to pick up the values.  No the registry wouldn't solve the
problem, it would become another mechanism for storing what I am already
storing within the application metadata.  The root problem is the
limited functionality within the log4net assembly with regards to
dynamically assigned variables/settings of non-string types.

 

Usually that is how I approach log management as well, just throw it
into a specific location that is only checked by analysts or engineers.
But this application is a synchronization application.  I need to give
the user the ability to not only check that their synchronization of
data is occurring, but also allow them to specify various attributes of
the logging process.  How long to do they want to keep their log files
for, how many log files do they want to maintain, where do they want to
store their log files at and what do they want their log files named?
[Just to name a few].

 

As for the flexibility, I tend to disagree.  I don't look at this as a
customized non-reusable method, I actually perceive this as a method
that could be used in later development.  Designed the right way, any
method can be ported into any other assembly, this is the beauty of OOP.
But as stated, it has to be designed the right way.  In order to reuse a
class/object, the class/object components have to live and breathe
within the class/object, only instances or reflections of the
class/object exist when in use by your application but never the actual
class/object.

 

Yeah I was just thinking out loud when I stated the XML thought process.
It again gets me another method of storing values, again the problem is
not the storage of the values, it is the limited functionality within
the log4net assembly with regards to dynamically assigned
variables/settings of  non-string types.  But I think, overall, you are
correct, the only correct answer in this case may be to alter the
log4net assembly to add the functionality that I am requiring.

 

Thanks again for your insights.

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Monday, June 08, 2009 7:55 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

Hi Richard,
 
please, dont think i am telling you that you are wrong - I am not. Its
just that I wouldnt have tried to do what you are doing with a .config
file is all.
 
I have always viewed .config files in .Net as files that hold
configuration. If I find that I need to change something on a regular
basis in the .config file, then I tend to turn it into a setting. I
guess in your situation, you could create the logfile itself
programtically based on a value in the .config file, which is the way I
have always veiwed these files should be used for. I think you could
also store the values you need in the registry should you want to.
 
When it comes to log management, I know where my logs are stored and how
they are named based on the application that is creating them, if I have
a deployment app I know exactly where to look to view the logfile for
that app, if I dont, then I can check the config to see where it is
pointing to (or where ever else the value may be). If it is generated in
the code then it would be a bit of a problem for someone who didnt know
where to look in the first place for it.
 
When it comes to flexibility, as soon as you start to control the
configuration of log4net in the code, then you loose the ability to
reuse your code in other apps that could need logging. For instance, I
have a logging library that I can use over and over again in different
projects. All I need to do is reference it in my code and apply the
relevant configuration in the web or app.config - but again, thats just
how I work and how I have seen the way log4net behaves. I do control
some of the config in the code with this lib, but this is because it
logs to a db and not to a file. So I set the connection string this way
(which I read from a config file).
 
However, in saying this, I can start to understand how you are thinking
about this. Most of the logging that I carry out isnt ever really
exposed to a user, its just there to give analysts and techs information
on whats going on (especially when its bad). I dont really need an end
user to control the formatting or location of the log itself etc, the
apps and services that use it just chug away in the background with
everyone oblivious to it.
 
In my previous email, I mentioned that you could create the settings as
an XML file in the code and have the .config read this information. But
you hit a problem here in so far that the .config will be read prior to
the XML being generated. But, you can work around this, as long as the
XML is generated to the same location each time, you can simply reload
the .config for the app picking up the config you just created. i think
the only thing I dont like about that is that you could just put the
config in the .config file from the get go.
 
Like I said before, I dont think at all that you are wrong, I was just
putting my views across. One other soloution would be to alter how
log4net works to give you the behaviour you want, I did something
similar myself to change the way db connections are used (I needed to
attach an analysis tool).




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 07:35:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

You mention in the best spirit of .Net, could you provide a little more
clarification?  I tend to feel that an assembly, log4net.dll in this
example, should be a black box, and how you interact with this black
box, should not affect the underlying codes buildability or stability.
The mere fact that you can use a separate configuration file for the
log4net assembly attests to this ability.  There are also others around
the internet who would tend to agree with my use of an external
configuration file.

 

You also mention the loss of flexibility, please expand upon this.  To
give a better understanding, using an application, how do you know where
the log files are stored and what they are named?  An application such
as Exchange or SQL will show you where the log files are (so far as you
know where to look inside the application interface), and not only that,
will allow for the end user to control some of the basic settings of the
log file [where it is stored, what it is named, will it be a rolling log
file (circular logging), etc. etc.].  If I am unable to use a
configuration file (regardless of app.config or log4net.config) to set
these values then my only recourse will be to programmatically control
the appender.  What are some pro's and con's you can think of?  What
functionality will I lose or gain?

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

I am not saying that the config file doesnt work, I was just suggesting
that the way you are trying to use the file may not be in the best
spirit of .Net.

You can control the configuration of log4net programatically, but you
will loose some of the flexibility that you need (going by the code and
config you mailed earlier). I have installatations that use this type of
appender, but I am happy enough specifiying the name of the logfile in
the config file itself, but again I can fully understand wanting to have
this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea.
.Net will lock the apps .config file though during execution, so you
would need to generate a .config to a seperate location and have the
app.config look this up etc. Once the xml has been generated, you would
need to reload the app.config (or web.config, whichever you are using).
This would then pick up the xml you have just generated.
 
How does that sound?




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org;
log4net-dev@logging.apache.org

As I stated in my post, it is not that the config file does not work, it
does, the main problem is that the %property method does not seem to
have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase
the method that sets the property in the
log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These
properties need to be set before the GetLogger method is called.  As
long as the properties are set before the GetLogger method (hence my two
sub calls to primeLogging [which fills the application variables with
data from either the My.Settings metabase or user entered data] and
configLog4Net [which uses the aforementioned
log4net.GlobalContext.Properties method to set the property values in
the Log4Net instance].  After the properties are set, the GetLogger
method fires and all of the properties are read and the Appenders are
generated.

 

All of my appenders work when I strip out all of the %properties that
are non string based.  Which means that I can set the log path and the
log filename dynamically but the boolean and int64 values will fail
because log4net does not cast these properties as anything other than
string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 
One thing you did mention was possibly creating the xml file within the
application, this is feasible (so long as log4net does not put a file
lock on the config file).  Another method I have been tinkering with
(would rather not use this method, but will if must) is to generate the
appender directly in the application by using the various getters and
setters for the RollingFileAppender.
 
Thanks for you input.

 

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being
generated by log4net? If they are, I dont think you are going to
succeed, the logfile needs to be created prior to logging commencing.
The properties you seem to be supplying wont exist at the point the you
are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not
simply create a file in the code if you really need to do this? I can
understand why you would want to dynamically name a log file, but the
way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") =
_MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/>  

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

Upgrade to Internet Explorer 8 Optimised for MSN. Download Now
<http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U> 

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 




Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Karim Bourouba <ka...@hotmail.com>.
Hi Richard,

 

glad to have been of assistance, if only in so far as being able to stimulate design :).

 

Thank god you have access to the source!




 



Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 08:28:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org







Karim,
 
Please don’t misinterpret my abrasiveness as ignorance or aggression.  It is merely there to help spur on some insightful conversation.
 
I better understand your point of view on .config files.  And really you are absolutely correct, a configuration file should hold the static configuration of the .NET application/assembly.  However, according to the log4net documentation, the use of a configuration allows for dynamic and monitored changes to occur; for example, during runtime the log file is renamed or relocated by the application.  The XML file which contains the log4net configuration is modified.  This change is then recognized by the log4net assembly and the appropriate changes are made dynamically and on the fly.  As far as the registry is concerned, it’s not out of the question, but I was hoping to stay out of it.  Still though, using the registry might have merit.  I still though have to deal with how to allow log4net to pick up the values.  No the registry wouldn’t solve the problem, it would become another mechanism for storing what I am already storing within the application metadata.  The root problem is the limited functionality within the log4net assembly with regards to dynamically assigned variables/settings of non-string types.
 
Usually that is how I approach log management as well, just throw it into a specific location that is only checked by analysts or engineers.  But this application is a synchronization application.  I need to give the user the ability to not only check that their synchronization of data is occurring, but also allow them to specify various attributes of the logging process.  How long to do they want to keep their log files for, how many log files do they want to maintain, where do they want to store their log files at and what do they want their log files named? [Just to name a few].
 
As for the flexibility, I tend to disagree.  I don’t look at this as a customized non-reusable method, I actually perceive this as a method that could be used in later development.  Designed the right way, any method can be ported into any other assembly, this is the beauty of OOP.  But as stated, it has to be designed the right way.  In order to reuse a class/object, the class/object components have to live and breathe within the class/object, only instances or reflections of the class/object exist when in use by your application but never the actual class/object.
 
Yeah I was just thinking out loud when I stated the XML thought process.  It again gets me another method of storing values, again the problem is not the storage of the values, it is the limited functionality within the log4net assembly with regards to dynamically assigned variables/settings of  non-string types.  But I think, overall, you are correct, the only correct answer in this case may be to alter the log4net assembly to add the functionality that I am requiring.
 
Thanks again for your insights.
 



-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 
http://www.we-are-it.com/


From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Monday, June 08, 2009 7:55 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender
 
Hi Richard,
 
please, dont think i am telling you that you are wrong - I am not. Its just that I wouldnt have tried to do what you are doing with a .config file is all.
 
I have always viewed .config files in .Net as files that hold configuration. If I find that I need to change something on a regular basis in the .config file, then I tend to turn it into a setting. I guess in your situation, you could create the logfile itself programtically based on a value in the .config file, which is the way I have always veiwed these files should be used for. I think you could also store the values you need in the registry should you want to.
 
When it comes to log management, I know where my logs are stored and how they are named based on the application that is creating them, if I have a deployment app I know exactly where to look to view the logfile for that app, if I dont, then I can check the config to see where it is pointing to (or where ever else the value may be). If it is generated in the code then it would be a bit of a problem for someone who didnt know where to look in the first place for it.
 
When it comes to flexibility, as soon as you start to control the configuration of log4net in the code, then you loose the ability to reuse your code in other apps that could need logging. For instance, I have a logging library that I can use over and over again in different projects. All I need to do is reference it in my code and apply the relevant configuration in the web or app.config - but again, thats just how I work and how I have seen the way log4net behaves. I do control some of the config in the code with this lib, but this is because it logs to a db and not to a file. So I set the connection string this way (which I read from a config file).
 
However, in saying this, I can start to understand how you are thinking about this. Most of the logging that I carry out isnt ever really exposed to a user, its just there to give analysts and techs information on whats going on (especially when its bad). I dont really need an end user to control the formatting or location of the log itself etc, the apps and services that use it just chug away in the background with everyone oblivious to it.
 
In my previous email, I mentioned that you could create the settings as an XML file in the code and have the .config read this information. But you hit a problem here in so far that the .config will be read prior to the XML being generated. But, you can work around this, as long as the XML is generated to the same location each time, you can simply reload the .config for the app picking up the config you just created. i think the only thing I dont like about that is that you could just put the config in the .config file from the get go.
 
Like I said before, I dont think at all that you are wrong, I was just putting my views across. One other soloution would be to alter how log4net works to give you the behaviour you want, I did something similar myself to change the way db connections are used (I needed to attach an analysis tool).




  



Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 07:35:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

You mention in the best spirit of .Net, could you provide a little more clarification?  I tend to feel that an assembly, log4net.dll in this example, should be a black box, and how you interact with this black box, should not affect the underlying codes buildability or stability.  The mere fact that you can use a separate configuration file for the log4net assembly attests to this ability.  There are also others around the internet who would tend to agree with my use of an external configuration file.
 
You also mention the loss of flexibility, please expand upon this.  To give a better understanding, using an application, how do you know where the log files are stored and what they are named?  An application such as Exchange or SQL will show you where the log files are (so far as you know where to look inside the application interface), and not only that, will allow for the end user to control some of the basic settings of the log file [where it is stored, what it is named, will it be a rolling log file (circular logging), etc. etc.].  If I am unable to use a configuration file (regardless of app.config or log4net.config) to set these values then my only recourse will be to programmatically control the appender.  What are some pro’s and con’s you can think of?  What functionality will I lose or gain?
 



-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 
http://www.we-are-it.com/


From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender
 
I am not saying that the config file doesnt work, I was just suggesting that the way you are trying to use the file may not be in the best spirit of .Net.

You can control the configuration of log4net programatically, but you will loose some of the flexibility that you need (going by the code and config you mailed earlier). I have installatations that use this type of appender, but I am happy enough specifiying the name of the logfile in the config file itself, but again I can fully understand wanting to have this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea. .Net will lock the apps .config file though during execution, so you would need to generate a .config to a seperate location and have the app.config look this up etc. Once the xml has been generated, you would need to reload the app.config (or web.config, whichever you are using). This would then pick up the xml you have just generated.
 
How does that sound?




  



Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org; log4net-dev@logging.apache.org


As I stated in my post, it is not that the config file does not work, it does, the main problem is that the %property method does not seem to have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase the method that sets the property in the log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These properties need to be set before the GetLogger method is called.  As long as the properties are set before the GetLogger method (hence my two sub calls to primeLogging [which fills the application variables with data from either the My.Settings metabase or user entered data] and configLog4Net [which uses the aforementioned log4net.GlobalContext.Properties method to set the property values in the Log4Net instance].  After the properties are set, the GetLogger method fires and all of the properties are read and the Appenders are generated.

 

All of my appenders work when I strip out all of the %properties that are non string based.  Which means that I can set the log path and the log filename dynamically but the boolean and int64 values will fail because log4net does not cast these properties as anything other than string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
 
One thing you did mention was possibly creating the xml file within the application, this is feasible (so long as log4net does not put a file lock on the config file).  Another method I have been tinkering with (would rather not use this method, but will if must) is to generate the appender directly in the application by using the various getters and setters for the RollingFileAppender.
 
Thanks for you input.

 

 



-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 



From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being generated by log4net? If they are, I dont think you are going to succeed, the logfile needs to be created prior to logging commencing. The properties you seem to be supplying wont exist at the point the you are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not simply create a file in the code if you really need to do this? I can understand why you would want to dynamically name a log file, but the way you are going about it probably isnt the best method.




  



Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my application, I have been tinkering with trying to set the boolean values for appendToFile and staticLogFileName as dynamic values.  These have a default value (currently stored in the My.Settings metadata).  My problem is that when I go to configure the values at runtime I get this error in my stack trace:
 
 
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.

The way that I am configuring the values is by trying to use the code displayed here:
 



'In Main         Private Shared Log As ILog          Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load                 '[...]                 primeLogging()                 configLog4Net()                 Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)                 Log.Info("This is the start of the application.")         End Sub          Private Sub primeLogging()                 If Not My.Settings.LogPath = "" Then                          _LogPath = My.Settings.LogPath                 Else                          _LogPath = My.Application.Info.DirectoryPath & "\Logs\"                 End If                  '[...]                  _MaxRollBacks = My.Settings.MaxRollBacks                 _MaxFileSize = My.Settings.MaxFileSize                  _isAppendToFile = My.Settings.isAppendToFile                 _isStaticLogFile = My.Settings.isStaticLogFile         End Sub          Private Sub configLog4Net()                 log4net.GlobalContext.Properties("LogPath") = _LogPath                 log4net.GlobalContext.Properties("LogName") = _LogName                 log4net.GlobalContext.Properties("RollStyle") = _tempRollStyle                 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks                 log4net.GlobalContext.Properties("MaxFileSize") = _MaxFileSize                 log4net.GlobalContext.Properties("isAppendToFile") = _isAppendToFile                 log4net.GlobalContext.Properties("isStaticLogFile") = _isStaticLogFile                 'My attempts to cast as a boolean (did not work)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isAppendToFile"), _isAppendToFile)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isStaticLogFile"), _isStaticLogFile)         End Sub 'In Log4Net.config (using a seperate configuration file for Log4Net)<?xml version="1.0" encoding="utf-8" ?><configuration>         <configSections>                 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />         </configSections>         <appSettings>                 <!-- To enable internal log4net logging specify the following appSettings key -->                 <add key="log4net.Internal.Debug" value="true"/>         </appSettings>         <!-- This section contains the log4net configuration settings -->         <log4net>                 <!-- Define some output appenders -->                 <appender name="SyncLogFile" type="log4net.Appender.RollingFileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Syncronizations\%property{LogName}" />                          <param name="DatePattern" value=".yyyy-MM-dd-tt.log"/>                          <appendToFile value="%property{isAppendToFile}" />                          <maxSizeRollBackups type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />                          <maximumFileSize type="log4net.Util.PatternString" value="%property{MaxFileSize}" />                          <rollingStyle type="log4net.Util.PatternString" value="%property{RollStyle}" />                          <staticLogFileName value="%property{isStaticLogFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />                          </layout>                 </appender>                 <appender name="ErrLogFile" type="log4net.Appender.FileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Errors\errLog.txt" />                          <sppendToFile value="%property{isAppendToFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="EventLog" type="log4net.Appender.EventLogAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <!-- Setup the root category, add the appenders and set the default level -->                 <root>                          <level value="ALL" />                          <appender-ref ref="SyncLogFile" />                          <appender-ref ref="ErrLogFile" />                          <appender-ref ref="ConsoleLog" />                          <appender-ref ref="EventLog" />                 </root>         </log4net></configuration>


All of my other appenders work (ConsoleLog, EventLog and ErrLogFile (when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-Do you have a disaster recovery plan for your servers? If not, ask about We Are IT's Total Rescue business continuity plan.
 



View your Twitter and Flickr updates from one place - Learn more!  Do you have a disaster recovery plan for your servers? If not, ask about We Are IT's Total Rescue business continuity plan.
 



View your Twitter and Flickr updates from one place – Learn more! Do you have a disaster recovery plan for your servers? If not, ask about We Are IT's Total Rescue business continuity plan.
 



Upgrade to Internet Explorer 8 Optimised for MSN. Download Now
Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.
_________________________________________________________________
Share your photos with Windows Live Photos – Free.
http://clk.atdmt.com/UKM/go/134665338/direct/01/

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
Karim,

 

Please don't misinterpret my abrasiveness as ignorance or aggression.
It is merely there to help spur on some insightful conversation.

 

I better understand your point of view on .config files.  And really you
are absolutely correct, a configuration file should hold the static
configuration of the .NET application/assembly.  However, according to
the log4net documentation, the use of a configuration allows for dynamic
and monitored changes to occur; for example, during runtime the log file
is renamed or relocated by the application.  The XML file which contains
the log4net configuration is modified.  This change is then recognized
by the log4net assembly and the appropriate changes are made dynamically
and on the fly.  As far as the registry is concerned, it's not out of
the question, but I was hoping to stay out of it.  Still though, using
the registry might have merit.  I still though have to deal with how to
allow log4net to pick up the values.  No the registry wouldn't solve the
problem, it would become another mechanism for storing what I am already
storing within the application metadata.  The root problem is the
limited functionality within the log4net assembly with regards to
dynamically assigned variables/settings of non-string types.

 

Usually that is how I approach log management as well, just throw it
into a specific location that is only checked by analysts or engineers.
But this application is a synchronization application.  I need to give
the user the ability to not only check that their synchronization of
data is occurring, but also allow them to specify various attributes of
the logging process.  How long to do they want to keep their log files
for, how many log files do they want to maintain, where do they want to
store their log files at and what do they want their log files named?
[Just to name a few].

 

As for the flexibility, I tend to disagree.  I don't look at this as a
customized non-reusable method, I actually perceive this as a method
that could be used in later development.  Designed the right way, any
method can be ported into any other assembly, this is the beauty of OOP.
But as stated, it has to be designed the right way.  In order to reuse a
class/object, the class/object components have to live and breathe
within the class/object, only instances or reflections of the
class/object exist when in use by your application but never the actual
class/object.

 

Yeah I was just thinking out loud when I stated the XML thought process.
It again gets me another method of storing values, again the problem is
not the storage of the values, it is the limited functionality within
the log4net assembly with regards to dynamically assigned
variables/settings of  non-string types.  But I think, overall, you are
correct, the only correct answer in this case may be to alter the
log4net assembly to add the functionality that I am requiring.

 

Thanks again for your insights.

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Monday, June 08, 2009 7:55 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

Hi Richard,
 
please, dont think i am telling you that you are wrong - I am not. Its
just that I wouldnt have tried to do what you are doing with a .config
file is all.
 
I have always viewed .config files in .Net as files that hold
configuration. If I find that I need to change something on a regular
basis in the .config file, then I tend to turn it into a setting. I
guess in your situation, you could create the logfile itself
programtically based on a value in the .config file, which is the way I
have always veiwed these files should be used for. I think you could
also store the values you need in the registry should you want to.
 
When it comes to log management, I know where my logs are stored and how
they are named based on the application that is creating them, if I have
a deployment app I know exactly where to look to view the logfile for
that app, if I dont, then I can check the config to see where it is
pointing to (or where ever else the value may be). If it is generated in
the code then it would be a bit of a problem for someone who didnt know
where to look in the first place for it.
 
When it comes to flexibility, as soon as you start to control the
configuration of log4net in the code, then you loose the ability to
reuse your code in other apps that could need logging. For instance, I
have a logging library that I can use over and over again in different
projects. All I need to do is reference it in my code and apply the
relevant configuration in the web or app.config - but again, thats just
how I work and how I have seen the way log4net behaves. I do control
some of the config in the code with this lib, but this is because it
logs to a db and not to a file. So I set the connection string this way
(which I read from a config file).
 
However, in saying this, I can start to understand how you are thinking
about this. Most of the logging that I carry out isnt ever really
exposed to a user, its just there to give analysts and techs information
on whats going on (especially when its bad). I dont really need an end
user to control the formatting or location of the log itself etc, the
apps and services that use it just chug away in the background with
everyone oblivious to it.
 
In my previous email, I mentioned that you could create the settings as
an XML file in the code and have the .config read this information. But
you hit a problem here in so far that the .config will be read prior to
the XML being generated. But, you can work around this, as long as the
XML is generated to the same location each time, you can simply reload
the .config for the app picking up the config you just created. i think
the only thing I dont like about that is that you could just put the
config in the .config file from the get go.
 
Like I said before, I dont think at all that you are wrong, I was just
putting my views across. One other soloution would be to alter how
log4net works to give you the behaviour you want, I did something
similar myself to change the way db connections are used (I needed to
attach an analysis tool).




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 07:35:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

You mention in the best spirit of .Net, could you provide a little more
clarification?  I tend to feel that an assembly, log4net.dll in this
example, should be a black box, and how you interact with this black
box, should not affect the underlying codes buildability or stability.
The mere fact that you can use a separate configuration file for the
log4net assembly attests to this ability.  There are also others around
the internet who would tend to agree with my use of an external
configuration file.

 

You also mention the loss of flexibility, please expand upon this.  To
give a better understanding, using an application, how do you know where
the log files are stored and what they are named?  An application such
as Exchange or SQL will show you where the log files are (so far as you
know where to look inside the application interface), and not only that,
will allow for the end user to control some of the basic settings of the
log file [where it is stored, what it is named, will it be a rolling log
file (circular logging), etc. etc.].  If I am unable to use a
configuration file (regardless of app.config or log4net.config) to set
these values then my only recourse will be to programmatically control
the appender.  What are some pro's and con's you can think of?  What
functionality will I lose or gain?

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

I am not saying that the config file doesnt work, I was just suggesting
that the way you are trying to use the file may not be in the best
spirit of .Net.

You can control the configuration of log4net programatically, but you
will loose some of the flexibility that you need (going by the code and
config you mailed earlier). I have installatations that use this type of
appender, but I am happy enough specifiying the name of the logfile in
the config file itself, but again I can fully understand wanting to have
this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea.
.Net will lock the apps .config file though during execution, so you
would need to generate a .config to a seperate location and have the
app.config look this up etc. Once the xml has been generated, you would
need to reload the app.config (or web.config, whichever you are using).
This would then pick up the xml you have just generated.
 
How does that sound?




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org;
log4net-dev@logging.apache.org

As I stated in my post, it is not that the config file does not work, it
does, the main problem is that the %property method does not seem to
have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase
the method that sets the property in the
log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These
properties need to be set before the GetLogger method is called.  As
long as the properties are set before the GetLogger method (hence my two
sub calls to primeLogging [which fills the application variables with
data from either the My.Settings metabase or user entered data] and
configLog4Net [which uses the aforementioned
log4net.GlobalContext.Properties method to set the property values in
the Log4Net instance].  After the properties are set, the GetLogger
method fires and all of the properties are read and the Appenders are
generated.

 

All of my appenders work when I strip out all of the %properties that
are non string based.  Which means that I can set the log path and the
log filename dynamically but the boolean and int64 values will fail
because log4net does not cast these properties as anything other than
string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 
One thing you did mention was possibly creating the xml file within the
application, this is feasible (so long as log4net does not put a file
lock on the config file).  Another method I have been tinkering with
(would rather not use this method, but will if must) is to generate the
appender directly in the application by using the various getters and
setters for the RollingFileAppender.
 
Thanks for you input.

 

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being
generated by log4net? If they are, I dont think you are going to
succeed, the logfile needs to be created prior to logging commencing.
The properties you seem to be supplying wont exist at the point the you
are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not
simply create a file in the code if you really need to do this? I can
understand why you would want to dynamically name a log file, but the
way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") =
_MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/>  

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

Upgrade to Internet Explorer 8 Optimised for MSN. Download Now
<http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U> 




Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
Karim,

 

Please don't misinterpret my abrasiveness as ignorance or aggression.
It is merely there to help spur on some insightful conversation.

 

I better understand your point of view on .config files.  And really you
are absolutely correct, a configuration file should hold the static
configuration of the .NET application/assembly.  However, according to
the log4net documentation, the use of a configuration allows for dynamic
and monitored changes to occur; for example, during runtime the log file
is renamed or relocated by the application.  The XML file which contains
the log4net configuration is modified.  This change is then recognized
by the log4net assembly and the appropriate changes are made dynamically
and on the fly.  As far as the registry is concerned, it's not out of
the question, but I was hoping to stay out of it.  Still though, using
the registry might have merit.  I still though have to deal with how to
allow log4net to pick up the values.  No the registry wouldn't solve the
problem, it would become another mechanism for storing what I am already
storing within the application metadata.  The root problem is the
limited functionality within the log4net assembly with regards to
dynamically assigned variables/settings of non-string types.

 

Usually that is how I approach log management as well, just throw it
into a specific location that is only checked by analysts or engineers.
But this application is a synchronization application.  I need to give
the user the ability to not only check that their synchronization of
data is occurring, but also allow them to specify various attributes of
the logging process.  How long to do they want to keep their log files
for, how many log files do they want to maintain, where do they want to
store their log files at and what do they want their log files named?
[Just to name a few].

 

As for the flexibility, I tend to disagree.  I don't look at this as a
customized non-reusable method, I actually perceive this as a method
that could be used in later development.  Designed the right way, any
method can be ported into any other assembly, this is the beauty of OOP.
But as stated, it has to be designed the right way.  In order to reuse a
class/object, the class/object components have to live and breathe
within the class/object, only instances or reflections of the
class/object exist when in use by your application but never the actual
class/object.

 

Yeah I was just thinking out loud when I stated the XML thought process.
It again gets me another method of storing values, again the problem is
not the storage of the values, it is the limited functionality within
the log4net assembly with regards to dynamically assigned
variables/settings of  non-string types.  But I think, overall, you are
correct, the only correct answer in this case may be to alter the
log4net assembly to add the functionality that I am requiring.

 

Thanks again for your insights.

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Monday, June 08, 2009 7:55 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

Hi Richard,
 
please, dont think i am telling you that you are wrong - I am not. Its
just that I wouldnt have tried to do what you are doing with a .config
file is all.
 
I have always viewed .config files in .Net as files that hold
configuration. If I find that I need to change something on a regular
basis in the .config file, then I tend to turn it into a setting. I
guess in your situation, you could create the logfile itself
programtically based on a value in the .config file, which is the way I
have always veiwed these files should be used for. I think you could
also store the values you need in the registry should you want to.
 
When it comes to log management, I know where my logs are stored and how
they are named based on the application that is creating them, if I have
a deployment app I know exactly where to look to view the logfile for
that app, if I dont, then I can check the config to see where it is
pointing to (or where ever else the value may be). If it is generated in
the code then it would be a bit of a problem for someone who didnt know
where to look in the first place for it.
 
When it comes to flexibility, as soon as you start to control the
configuration of log4net in the code, then you loose the ability to
reuse your code in other apps that could need logging. For instance, I
have a logging library that I can use over and over again in different
projects. All I need to do is reference it in my code and apply the
relevant configuration in the web or app.config - but again, thats just
how I work and how I have seen the way log4net behaves. I do control
some of the config in the code with this lib, but this is because it
logs to a db and not to a file. So I set the connection string this way
(which I read from a config file).
 
However, in saying this, I can start to understand how you are thinking
about this. Most of the logging that I carry out isnt ever really
exposed to a user, its just there to give analysts and techs information
on whats going on (especially when its bad). I dont really need an end
user to control the formatting or location of the log itself etc, the
apps and services that use it just chug away in the background with
everyone oblivious to it.
 
In my previous email, I mentioned that you could create the settings as
an XML file in the code and have the .config read this information. But
you hit a problem here in so far that the .config will be read prior to
the XML being generated. But, you can work around this, as long as the
XML is generated to the same location each time, you can simply reload
the .config for the app picking up the config you just created. i think
the only thing I dont like about that is that you could just put the
config in the .config file from the get go.
 
Like I said before, I dont think at all that you are wrong, I was just
putting my views across. One other soloution would be to alter how
log4net works to give you the behaviour you want, I did something
similar myself to change the way db connections are used (I needed to
attach an analysis tool).




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 07:35:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

You mention in the best spirit of .Net, could you provide a little more
clarification?  I tend to feel that an assembly, log4net.dll in this
example, should be a black box, and how you interact with this black
box, should not affect the underlying codes buildability or stability.
The mere fact that you can use a separate configuration file for the
log4net assembly attests to this ability.  There are also others around
the internet who would tend to agree with my use of an external
configuration file.

 

You also mention the loss of flexibility, please expand upon this.  To
give a better understanding, using an application, how do you know where
the log files are stored and what they are named?  An application such
as Exchange or SQL will show you where the log files are (so far as you
know where to look inside the application interface), and not only that,
will allow for the end user to control some of the basic settings of the
log file [where it is stored, what it is named, will it be a rolling log
file (circular logging), etc. etc.].  If I am unable to use a
configuration file (regardless of app.config or log4net.config) to set
these values then my only recourse will be to programmatically control
the appender.  What are some pro's and con's you can think of?  What
functionality will I lose or gain?

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

I am not saying that the config file doesnt work, I was just suggesting
that the way you are trying to use the file may not be in the best
spirit of .Net.

You can control the configuration of log4net programatically, but you
will loose some of the flexibility that you need (going by the code and
config you mailed earlier). I have installatations that use this type of
appender, but I am happy enough specifiying the name of the logfile in
the config file itself, but again I can fully understand wanting to have
this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea.
.Net will lock the apps .config file though during execution, so you
would need to generate a .config to a seperate location and have the
app.config look this up etc. Once the xml has been generated, you would
need to reload the app.config (or web.config, whichever you are using).
This would then pick up the xml you have just generated.
 
How does that sound?




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org;
log4net-dev@logging.apache.org

As I stated in my post, it is not that the config file does not work, it
does, the main problem is that the %property method does not seem to
have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase
the method that sets the property in the
log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These
properties need to be set before the GetLogger method is called.  As
long as the properties are set before the GetLogger method (hence my two
sub calls to primeLogging [which fills the application variables with
data from either the My.Settings metabase or user entered data] and
configLog4Net [which uses the aforementioned
log4net.GlobalContext.Properties method to set the property values in
the Log4Net instance].  After the properties are set, the GetLogger
method fires and all of the properties are read and the Appenders are
generated.

 

All of my appenders work when I strip out all of the %properties that
are non string based.  Which means that I can set the log path and the
log filename dynamically but the boolean and int64 values will fail
because log4net does not cast these properties as anything other than
string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 
One thing you did mention was possibly creating the xml file within the
application, this is feasible (so long as log4net does not put a file
lock on the config file).  Another method I have been tinkering with
(would rather not use this method, but will if must) is to generate the
appender directly in the application by using the various getters and
setters for the RollingFileAppender.
 
Thanks for you input.

 

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being
generated by log4net? If they are, I dont think you are going to
succeed, the logfile needs to be created prior to logging commencing.
The properties you seem to be supplying wont exist at the point the you
are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not
simply create a file in the code if you really need to do this? I can
understand why you would want to dynamically name a log file, but the
way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") =
_MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/>  

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

Upgrade to Internet Explorer 8 Optimised for MSN. Download Now
<http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U> 




Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Karim Bourouba <ka...@hotmail.com>.
Hi Richard,

 

please, dont think i am telling you that you are wrong - I am not. Its just that I wouldnt have tried to do what you are doing with a .config file is all.

 

I have always viewed .config files in .Net as files that hold configuration. If I find that I need to change something on a regular basis in the .config file, then I tend to turn it into a setting. I guess in your situation, you could create the logfile itself programtically based on a value in the .config file, which is the way I have always veiwed these files should be used for. I think you could also store the values you need in the registry should you want to.

 

When it comes to log management, I know where my logs are stored and how they are named based on the application that is creating them, if I have a deployment app I know exactly where to look to view the logfile for that app, if I dont, then I can check the config to see where it is pointing to (or where ever else the value may be). If it is generated in the code then it would be a bit of a problem for someone who didnt know where to look in the first place for it.

 

When it comes to flexibility, as soon as you start to control the configuration of log4net in the code, then you loose the ability to reuse your code in other apps that could need logging. For instance, I have a logging library that I can use over and over again in different projects. All I need to do is reference it in my code and apply the relevant configuration in the web or app.config - but again, thats just how I work and how I have seen the way log4net behaves. I do control some of the config in the code with this lib, but this is because it logs to a db and not to a file. So I set the connection string this way (which I read from a config file).

 

However, in saying this, I can start to understand how you are thinking about this. Most of the logging that I carry out isnt ever really exposed to a user, its just there to give analysts and techs information on whats going on (especially when its bad). I dont really need an end user to control the formatting or location of the log itself etc, the apps and services that use it just chug away in the background with everyone oblivious to it.

 

In my previous email, I mentioned that you could create the settings as an XML file in the code and have the .config read this information. But you hit a problem here in so far that the .config will be read prior to the XML being generated. But, you can work around this, as long as the XML is generated to the same location each time, you can simply reload the .config for the app picking up the config you just created. i think the only thing I dont like about that is that you could just put the config in the .config file from the get go.

 

Like I said before, I dont think at all that you are wrong, I was just putting my views across. One other soloution would be to alter how log4net works to give you the behaviour you want, I did something similar myself to change the way db connections are used (I needed to attach an analysis tool).




 



Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Mon, 8 Jun 2009 07:35:08 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org







You mention in the best spirit of .Net, could you provide a little more clarification?  I tend to feel that an assembly, log4net.dll in this example, should be a black box, and how you interact with this black box, should not affect the underlying codes buildability or stability.  The mere fact that you can use a separate configuration file for the log4net assembly attests to this ability.  There are also others around the internet who would tend to agree with my use of an external configuration file.
 
You also mention the loss of flexibility, please expand upon this.  To give a better understanding, using an application, how do you know where the log files are stored and what they are named?  An application such as Exchange or SQL will show you where the log files are (so far as you know where to look inside the application interface), and not only that, will allow for the end user to control some of the basic settings of the log file [where it is stored, what it is named, will it be a rolling log file (circular logging), etc. etc.].  If I am unable to use a configuration file (regardless of app.config or log4net.config) to set these values then my only recourse will be to programmatically control the appender.  What are some pro’s and con’s you can think of?  What functionality will I lose or gain?
 



-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 
http://www.we-are-it.com/


From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender
 
I am not saying that the config file doesnt work, I was just suggesting that the way you are trying to use the file may not be in the best spirit of .Net.

You can control the configuration of log4net programatically, but you will loose some of the flexibility that you need (going by the code and config you mailed earlier). I have installatations that use this type of appender, but I am happy enough specifiying the name of the logfile in the config file itself, but again I can fully understand wanting to have this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea. .Net will lock the apps .config file though during execution, so you would need to generate a .config to a seperate location and have the app.config look this up etc. Once the xml has been generated, you would need to reload the app.config (or web.config, whichever you are using). This would then pick up the xml you have just generated.
 
How does that sound?




  



Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org; log4net-dev@logging.apache.org


As I stated in my post, it is not that the config file does not work, it does, the main problem is that the %property method does not seem to have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase the method that sets the property in the log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These properties need to be set before the GetLogger method is called.  As long as the properties are set before the GetLogger method (hence my two sub calls to primeLogging [which fills the application variables with data from either the My.Settings metabase or user entered data] and configLog4Net [which uses the aforementioned log4net.GlobalContext.Properties method to set the property values in the Log4Net instance].  After the properties are set, the GetLogger method fires and all of the properties are read and the Appenders are generated.

 

All of my appenders work when I strip out all of the %properties that are non string based.  Which means that I can set the log path and the log filename dynamically but the boolean and int64 values will fail because log4net does not cast these properties as anything other than string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
 
One thing you did mention was possibly creating the xml file within the application, this is feasible (so long as log4net does not put a file lock on the config file).  Another method I have been tinkering with (would rather not use this method, but will if must) is to generate the appender directly in the application by using the various getters and setters for the RollingFileAppender.
 
Thanks for you input.

 

 



-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 



From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being generated by log4net? If they are, I dont think you are going to succeed, the logfile needs to be created prior to logging commencing. The properties you seem to be supplying wont exist at the point the you are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not simply create a file in the code if you really need to do this? I can understand why you would want to dynamically name a log file, but the way you are going about it probably isnt the best method.




  



Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my application, I have been tinkering with trying to set the boolean values for appendToFile and staticLogFileName as dynamic values.  These have a default value (currently stored in the My.Settings metadata).  My problem is that when I go to configure the values at runtime I get this error in my stack trace:
 
 
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.

The way that I am configuring the values is by trying to use the code displayed here:
 



'In Main         Private Shared Log As ILog          Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load                 '[...]                 primeLogging()                 configLog4Net()                 Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)                 Log.Info("This is the start of the application.")         End Sub          Private Sub primeLogging()                 If Not My.Settings.LogPath = "" Then                          _LogPath = My.Settings.LogPath                 Else                          _LogPath = My.Application.Info.DirectoryPath & "\Logs\"                 End If                  '[...]                  _MaxRollBacks = My.Settings.MaxRollBacks                 _MaxFileSize = My.Settings.MaxFileSize                  _isAppendToFile = My.Settings.isAppendToFile                 _isStaticLogFile = My.Settings.isStaticLogFile         End Sub          Private Sub configLog4Net()                 log4net.GlobalContext.Properties("LogPath") = _LogPath                 log4net.GlobalContext.Properties("LogName") = _LogName                 log4net.GlobalContext.Properties("RollStyle") = _tempRollStyle                 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks                 log4net.GlobalContext.Properties("MaxFileSize") = _MaxFileSize                 log4net.GlobalContext.Properties("isAppendToFile") = _isAppendToFile                 log4net.GlobalContext.Properties("isStaticLogFile") = _isStaticLogFile                 'My attempts to cast as a boolean (did not work)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isAppendToFile"), _isAppendToFile)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isStaticLogFile"), _isStaticLogFile)         End Sub 'In Log4Net.config (using a seperate configuration file for Log4Net)<?xml version="1.0" encoding="utf-8" ?><configuration>         <configSections>                 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />         </configSections>         <appSettings>                 <!-- To enable internal log4net logging specify the following appSettings key -->                 <add key="log4net.Internal.Debug" value="true"/>         </appSettings>         <!-- This section contains the log4net configuration settings -->         <log4net>                 <!-- Define some output appenders -->                 <appender name="SyncLogFile" type="log4net.Appender.RollingFileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Syncronizations\%property{LogName}" />                          <param name="DatePattern" value=".yyyy-MM-dd-tt.log"/>                          <appendToFile value="%property{isAppendToFile}" />                          <maxSizeRollBackups type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />                          <maximumFileSize type="log4net.Util.PatternString" value="%property{MaxFileSize}" />                          <rollingStyle type="log4net.Util.PatternString" value="%property{RollStyle}" />                          <staticLogFileName value="%property{isStaticLogFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />                          </layout>                 </appender>                 <appender name="ErrLogFile" type="log4net.Appender.FileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Errors\errLog.txt" />                          <sppendToFile value="%property{isAppendToFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="EventLog" type="log4net.Appender.EventLogAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <!-- Setup the root category, add the appenders and set the default level -->                 <root>                          <level value="ALL" />                          <appender-ref ref="SyncLogFile" />                          <appender-ref ref="ErrLogFile" />                          <appender-ref ref="ConsoleLog" />                          <appender-ref ref="EventLog" />                 </root>         </log4net></configuration>


All of my other appenders work (ConsoleLog, EventLog and ErrLogFile (when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-Do you have a disaster recovery plan for your servers? If not, ask about We Are IT's Total Rescue business continuity plan.
 



View your Twitter and Flickr updates from one place - Learn more!  Do you have a disaster recovery plan for your servers? If not, ask about We Are IT's Total Rescue business continuity plan.
 



View your Twitter and Flickr updates from one place – Learn more!
Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.
_________________________________________________________________
Get the best of MSN on your mobile
http://clk.atdmt.com/UKM/go/147991039/direct/01/

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
You mention in the best spirit of .Net, could you provide a little more
clarification?  I tend to feel that an assembly, log4net.dll in this
example, should be a black box, and how you interact with this black
box, should not affect the underlying codes buildability or stability.
The mere fact that you can use a separate configuration file for the
log4net assembly attests to this ability.  There are also others around
the internet who would tend to agree with my use of an external
configuration file.

 

You also mention the loss of flexibility, please expand upon this.  To
give a better understanding, using an application, how do you know where
the log files are stored and what they are named?  An application such
as Exchange or SQL will show you where the log files are (so far as you
know where to look inside the application interface), and not only that,
will allow for the end user to control some of the basic settings of the
log file [where it is stored, what it is named, will it be a rolling log
file (circular logging), etc. etc.].  If I am unable to use a
configuration file (regardless of app.config or log4net.config) to set
these values then my only recourse will be to programmatically control
the appender.  What are some pro's and con's you can think of?  What
functionality will I lose or gain?

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

I am not saying that the config file doesnt work, I was just suggesting
that the way you are trying to use the file may not be in the best
spirit of .Net.

You can control the configuration of log4net programatically, but you
will loose some of the flexibility that you need (going by the code and
config you mailed earlier). I have installatations that use this type of
appender, but I am happy enough specifiying the name of the logfile in
the config file itself, but again I can fully understand wanting to have
this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea.
.Net will lock the apps .config file though during execution, so you
would need to generate a .config to a seperate location and have the
app.config look this up etc. Once the xml has been generated, you would
need to reload the app.config (or web.config, whichever you are using).
This would then pick up the xml you have just generated.
 
How does that sound?




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org;
log4net-dev@logging.apache.org

As I stated in my post, it is not that the config file does not work, it
does, the main problem is that the %property method does not seem to
have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase
the method that sets the property in the
log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These
properties need to be set before the GetLogger method is called.  As
long as the properties are set before the GetLogger method (hence my two
sub calls to primeLogging [which fills the application variables with
data from either the My.Settings metabase or user entered data] and
configLog4Net [which uses the aforementioned
log4net.GlobalContext.Properties method to set the property values in
the Log4Net instance].  After the properties are set, the GetLogger
method fires and all of the properties are read and the Appenders are
generated.

 

All of my appenders work when I strip out all of the %properties that
are non string based.  Which means that I can set the log path and the
log filename dynamically but the boolean and int64 values will fail
because log4net does not cast these properties as anything other than
string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 
One thing you did mention was possibly creating the xml file within the
application, this is feasible (so long as log4net does not put a file
lock on the config file).  Another method I have been tinkering with
(would rather not use this method, but will if must) is to generate the
appender directly in the application by using the various getters and
setters for the RollingFileAppender.
 
Thanks for you input.

 

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being
generated by log4net? If they are, I dont think you are going to
succeed, the logfile needs to be created prior to logging commencing.
The properties you seem to be supplying wont exist at the point the you
are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not
simply create a file in the code if you really need to do this? I can
understand why you would want to dynamically name a log file, but the
way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") =
_MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/>  

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 




Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
You mention in the best spirit of .Net, could you provide a little more
clarification?  I tend to feel that an assembly, log4net.dll in this
example, should be a black box, and how you interact with this black
box, should not affect the underlying codes buildability or stability.
The mere fact that you can use a separate configuration file for the
log4net assembly attests to this ability.  There are also others around
the internet who would tend to agree with my use of an external
configuration file.

 

You also mention the loss of flexibility, please expand upon this.  To
give a better understanding, using an application, how do you know where
the log files are stored and what they are named?  An application such
as Exchange or SQL will show you where the log files are (so far as you
know where to look inside the application interface), and not only that,
will allow for the end user to control some of the basic settings of the
log file [where it is stored, what it is named, will it be a rolling log
file (circular logging), etc. etc.].  If I am unable to use a
configuration file (regardless of app.config or log4net.config) to set
these values then my only recourse will be to programmatically control
the appender.  What are some pro's and con's you can think of?  What
functionality will I lose or gain?

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Karim Bourouba [mailto:karym6@hotmail.com] 
Sent: Saturday, June 06, 2009 2:16 AM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 

I am not saying that the config file doesnt work, I was just suggesting
that the way you are trying to use the file may not be in the best
spirit of .Net.

You can control the configuration of log4net programatically, but you
will loose some of the flexibility that you need (going by the code and
config you mailed earlier). I have installatations that use this type of
appender, but I am happy enough specifiying the name of the logfile in
the config file itself, but again I can fully understand wanting to have
this dynamically created.
 
The last point you mention, about creating the xml, yes its a nice idea.
.Net will lock the apps .config file though during execution, so you
would need to generate a .config to a seperate location and have the
app.config look this up etc. Once the xml has been generated, you would
need to reload the app.config (or web.config, whichever you are using).
This would then pick up the xml you have just generated.
 
How does that sound?




  

________________________________

Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org;
log4net-dev@logging.apache.org

As I stated in my post, it is not that the config file does not work, it
does, the main problem is that the %property method does not seem to
have the ability to cast as anything other than a string.

 

I have tried to cast it directly in the program with no success becuase
the method that sets the property in the
log4net.GlobalContext.Properties sets the input as a string value.

 

But to clarify a few things that you mentioned.

 

The properties are set in the application at or durning runtime.  These
properties need to be set before the GetLogger method is called.  As
long as the properties are set before the GetLogger method (hence my two
sub calls to primeLogging [which fills the application variables with
data from either the My.Settings metabase or user entered data] and
configLog4Net [which uses the aforementioned
log4net.GlobalContext.Properties method to set the property values in
the Log4Net instance].  After the properties are set, the GetLogger
method fires and all of the properties are read and the Appenders are
generated.

 

All of my appenders work when I strip out all of the %properties that
are non string based.  Which means that I can set the log path and the
log filename dynamically but the boolean and int64 values will fail
because log4net does not cast these properties as anything other than
string values, hence the error in the stack trace:

 

Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 
One thing you did mention was possibly creating the xml file within the
application, this is feasible (so long as log4net does not put a file
lock on the config file).  Another method I have been tinkering with
(would rather not use this method, but will if must) is to generate the
appender directly in the application by using the various getters and
setters for the RollingFileAppender.
 
Thanks for you input.

 

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

 

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender


The properties you are using to create the logfile name, are these being
generated by log4net? If they are, I dont think you are going to
succeed, the logfile needs to be created prior to logging commencing.
The properties you seem to be supplying wont exist at the point the you
are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not
simply create a file in the code if you really need to do this? I can
understand why you would want to dynamically name a log file, but the
way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") =
_MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/>  

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.

 

________________________________

View your Twitter and Flickr updates from one place - Learn more!
<http://clk.atdmt.com/UKM/go/137984870/direct/01/> 




Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Karim Bourouba <ka...@hotmail.com>.
I am not saying that the config file doesnt work, I was just suggesting that the way you are trying to use the file may not be in the best spirit of .Net.

You can control the configuration of log4net programatically, but you will loose some of the flexibility that you need (going by the code and config you mailed earlier). I have installatations that use this type of appender, but I am happy enough specifiying the name of the logfile in the config file itself, but again I can fully understand wanting to have this dynamically created.

 

The last point you mention, about creating the xml, yes its a nice idea. .Net will lock the apps .config file though during execution, so you would need to generate a .config to a seperate location and have the app.config look this up etc. Once the xml has been generated, you would need to reload the app.config (or web.config, whichever you are using). This would then pick up the xml you have just generated.

 

How does that sound?




 



Subject: RE: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 19:24:10 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-user@logging.apache.org; log4net-dev@logging.apache.org





As I stated in my post, it is not that the config file does not work, it does, the main problem is that the %property method does not seem to have the ability to cast as anything other than a string.
 
I have tried to cast it directly in the program with no success becuase the method that sets the property in the log4net.GlobalContext.Properties sets the input as a string value.
 
But to clarify a few things that you mentioned.
 
The properties are set in the application at or durning runtime.  These properties need to be set before the GetLogger method is called.  As long as the properties are set before the GetLogger method (hence my two sub calls to primeLogging [which fills the application variables with data from either the My.Settings metabase or user entered data] and configLog4Net [which uses the aforementioned log4net.GlobalContext.Properties method to set the property values in the Log4Net instance].  After the properties are set, the GetLogger method fires and all of the properties are read and the Appenders are generated.
 
All of my appenders work when I strip out all of the %properties that are non string based.  Which means that I can set the log path and the log filename dynamically but the boolean and int64 values will fail because log4net does not cast these properties as anything other than string values, hence the error in the stack trace:
 
Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
 

One thing you did mention was possibly creating the xml file within the application, this is feasible (so long as log4net does not put a file lock on the config file).  Another method I have been tinkering with (would rather not use this method, but will if must) is to generate the appender directly in the application by using the various getters and setters for the RollingFileAppender.

 

Thanks for you input.



 


-Richard Fouts
 
Senior OS/Network Specialist
We Are IT
11040 Holmes Road
Kansas City, MO  64131
Phone: (816) 941-6800
Fax: (816) 941-4420
 
http://www.we-are-it.com/



From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender



The properties you are using to create the logfile name, are these being generated by log4net? If they are, I dont think you are going to succeed, the logfile needs to be created prior to logging commencing. The properties you seem to be supplying wont exist at the point the you are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not simply create a file in the code if you really need to do this? I can understand why you would want to dynamically name a log file, but the way you are going about it probably isnt the best method.




  


Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org





I have ran into a "small" brick wall.  Hoping that I can find a couple of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my application, I have been tinkering with trying to set the boolean values for appendToFile and staticLogFileName as dynamic values.  These have a default value (currently stored in the My.Settings metadata).  My problem is that when I go to configure the values at runtime I get this error in my stack trace:
 
 
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.

The way that I am configuring the values is by trying to use the code displayed here:
 



'In Main         Private Shared Log As ILog          Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load                 '[...]                 primeLogging()                 configLog4Net()                 Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)                 Log.Info("This is the start of the application.")         End Sub          Private Sub primeLogging()                 If Not My.Settings.LogPath = "" Then                          _LogPath = My.Settings.LogPath                 Else                          _LogPath = My.Application.Info.DirectoryPath & "\Logs\"                 End If                  '[...]                  _MaxRollBacks = My.Settings.MaxRollBacks                 _MaxFileSize = My.Settings.MaxFileSize                  _isAppendToFile = My.Settings.isAppendToFile                 _isStaticLogFile = My.Settings.isStaticLogFile         End Sub          Private Sub configLog4Net()                 log4net.GlobalContext.Properties("LogPath") = _LogPath                 log4net.GlobalContext.Properties("LogName") = _LogName                 log4net.GlobalContext.Properties("RollStyle") = _tempRollStyle                 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks                 log4net.GlobalContext.Properties("MaxFileSize") = _MaxFileSize                 log4net.GlobalContext.Properties("isAppendToFile") = _isAppendToFile                 log4net.GlobalContext.Properties("isStaticLogFile") = _isStaticLogFile                 'My attempts to cast as a boolean (did not work)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isAppendToFile"), _isAppendToFile)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isStaticLogFile"), _isStaticLogFile)         End Sub 'In Log4Net.config (using a seperate configuration file for Log4Net)<?xml version="1.0" encoding="utf-8" ?><configuration>         <configSections>                 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />         </configSections>         <appSettings>                 <!-- To enable internal log4net logging specify the following appSettings key -->                 <add key="log4net.Internal.Debug" value="true"/>         </appSettings>         <!-- This section contains the log4net configuration settings -->         <log4net>                 <!-- Define some output appenders -->                 <appender name="SyncLogFile" type="log4net.Appender.RollingFileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Syncronizations\%property{LogName}" />                          <param name="DatePattern" value=".yyyy-MM-dd-tt.log"/>                          <appendToFile value="%property{isAppendToFile}" />                          <maxSizeRollBackups type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />                          <maximumFileSize type="log4net.Util.PatternString" value="%property{MaxFileSize}" />                          <rollingStyle type="log4net.Util.PatternString" value="%property{RollStyle}" />                          <staticLogFileName value="%property{isStaticLogFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />                          </layout>                 </appender>                 <appender name="ErrLogFile" type="log4net.Appender.FileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Errors\errLog.txt" />                          <sppendToFile value="%property{isAppendToFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="EventLog" type="log4net.Appender.EventLogAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <!-- Setup the root category, add the appenders and set the default level -->                 <root>                          <level value="ALL" />                          <appender-ref ref="SyncLogFile" />                          <appender-ref ref="ErrLogFile" />                          <appender-ref ref="ConsoleLog" />                          <appender-ref ref="EventLog" />                 </root>         </log4net></configuration>


All of my other appenders work (ConsoleLog, EventLog and ErrLogFile (when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.


View your Twitter and Flickr updates from one place - Learn more! 
Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.
_________________________________________________________________
Share your photos with Windows Live Photos – Free.
http://clk.atdmt.com/UKM/go/134665338/direct/01/

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
As I stated in my post, it is not that the config file does not work, it does, the main problem is that the %property method does not seem to have the ability to cast as anything other than a string.
 
I have tried to cast it directly in the program with no success becuase the method that sets the property in the log4net.GlobalContext.Properties sets the input as a string value.
 
But to clarify a few things that you mentioned.
 
The properties are set in the application at or durning runtime.  These properties need to be set before the GetLogger method is called.  As long as the properties are set before the GetLogger method (hence my two sub calls to primeLogging [which fills the application variables with data from either the My.Settings metabase or user entered data] and configLog4Net [which uses the aforementioned log4net.GlobalContext.Properties method to set the property values in the Log4Net instance].  After the properties are set, the GetLogger method fires and all of the properties are read and the Appenders are generated.
 
All of my appenders work when I strip out all of the %properties that are non string based.  Which means that I can set the log path and the log filename dynamically but the boolean and int64 values will fail because log4net does not cast these properties as anything other than string values, hence the error in the stack trace:
 
Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 

One thing you did mention was possibly creating the xml file within the application, this is feasible (so long as log4net does not put a file lock on the config file).  Another method I have been tinkering with (would rather not use this method, but will if must) is to generate the appender directly in the application by using the various getters and setters for the RollingFileAppender.

 

Thanks for you input.


 
-Richard Fouts
 
Senior OS/Network Specialist
We Are IT
11040 Holmes Road
Kansas City, MO  64131
Phone: (816) 941-6800
Fax: (816) 941-4420
 
http://www.we-are-it.com/

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender



The properties you are using to create the logfile name, are these being generated by log4net? If they are, I dont think you are going to succeed, the logfile needs to be created prior to logging commencing. The properties you seem to be supplying wont exist at the point the you are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not simply create a file in the code if you really need to do this? I can understand why you would want to dynamically name a log file, but the way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org



I have ran into a "small" brick wall.  Hoping that I can find a couple of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my application, I have been tinkering with trying to set the boolean values for appendToFile and staticLogFileName as dynamic values.  These have a default value (currently stored in the My.Settings metadata).  My problem is that when I go to configure the values at runtime I get this error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.

The way that I am configuring the values is by trying to use the code displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath & "\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") = _tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") = _MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") = _isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") = _isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isAppendToFile"), _isAppendToFile)
                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings -->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile" type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern" value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile value="%property{isAppendToFile}" />
                          <maxSizeRollBackups type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />
                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile" type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />
                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog" type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile (when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

________________________________

View your Twitter and Flickr updates from one place - Learn more! <http://clk.atdmt.com/UKM/go/137984870/direct/01/>  



Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
As I stated in my post, it is not that the config file does not work, it does, the main problem is that the %property method does not seem to have the ability to cast as anything other than a string.
 
I have tried to cast it directly in the program with no success becuase the method that sets the property in the log4net.GlobalContext.Properties sets the input as a string value.
 
But to clarify a few things that you mentioned.
 
The properties are set in the application at or durning runtime.  These properties need to be set before the GetLogger method is called.  As long as the properties are set before the GetLogger method (hence my two sub calls to primeLogging [which fills the application variables with data from either the My.Settings metabase or user entered data] and configLog4Net [which uses the aforementioned log4net.GlobalContext.Properties method to set the property values in the Log4Net instance].  After the properties are set, the GetLogger method fires and all of the properties are read and the Appenders are generated.
 
All of my appenders work when I strip out all of the %properties that are non string based.  Which means that I can set the log path and the log filename dynamically but the boolean and int64 values will fail because log4net does not cast these properties as anything other than string values, hence the error in the stack trace:
 
Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.

 

One thing you did mention was possibly creating the xml file within the application, this is feasible (so long as log4net does not put a file lock on the config file).  Another method I have been tinkering with (would rather not use this method, but will if must) is to generate the appender directly in the application by using the various getters and setters for the RollingFileAppender.

 

Thanks for you input.


 
-Richard Fouts
 
Senior OS/Network Specialist
We Are IT
11040 Holmes Road
Kansas City, MO  64131
Phone: (816) 941-6800
Fax: (816) 941-4420
 
http://www.we-are-it.com/

________________________________

From: Karim Bourouba [mailto:karym6@hotmail.com]
Sent: Fri 6/5/2009 1:20 PM
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Subject: RE: How do I use dynamic boolean values on RollingFileAppender



The properties you are using to create the logfile name, are these being generated by log4net? If they are, I dont think you are going to succeed, the logfile needs to be created prior to logging commencing. The properties you seem to be supplying wont exist at the point the you are trying to write the file.
 
Also, is the .config file the best place to be doing this? Why not simply create a file in the code if you really need to do this? I can understand why you would want to dynamically name a log file, but the way you are going about it probably isnt the best method.




  

________________________________

Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org



I have ran into a "small" brick wall.  Hoping that I can find a couple of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my application, I have been tinkering with trying to set the boolean values for appendToFile and staticLogFileName as dynamic values.  These have a default value (currently stored in the My.Settings metadata).  My problem is that when I go to configure the values at runtime I get this error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.

The way that I am configuring the values is by trying to use the code displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath & "\Logs\"
                 End If
 
                 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") = _tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") = _MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") = _isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") = _isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isAppendToFile"), _isAppendToFile)
                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings -->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile" type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern" value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile value="%property{isAppendToFile}" />
                          <maxSizeRollBackups type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />
                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile" type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />
                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog" type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile (when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

________________________________

View your Twitter and Flickr updates from one place - Learn more! <http://clk.atdmt.com/UKM/go/137984870/direct/01/>  



Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Karim Bourouba <ka...@hotmail.com>.

The properties you are using to create the logfile name, are these being generated by log4net? If they are, I dont think you are going to succeed, the logfile needs to be created prior to logging commencing. The properties you seem to be supplying wont exist at the point the you are trying to write the file.

 

Also, is the .config file the best place to be doing this? Why not simply create a file in the code if you really need to do this? I can understand why you would want to dynamically name a log file, but the way you are going about it probably isnt the best method.




 



Subject: How do I use dynamic boolean values on RollingFileAppender
Date: Fri, 5 Jun 2009 10:01:18 -0500
From: rfouts@we-are-it.com
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org





I have ran into a "small" brick wall.  Hoping that I can find a couple of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my application, I have been tinkering with trying to set the boolean values for appendToFile and staticLogFileName as dynamic values.  These have a default value (currently stored in the My.Settings metadata).  My problem is that when I go to configure the values at runtime I get this error in my stack trace:
 
 
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not found.

The way that I am configuring the values is by trying to use the code displayed here:
 



'In Main         Private Shared Log As ILog          Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load                 '[...]                 primeLogging()                 configLog4Net()                 Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)                 Log.Info("This is the start of the application.")         End Sub          Private Sub primeLogging()                 If Not My.Settings.LogPath = "" Then                          _LogPath = My.Settings.LogPath                 Else                          _LogPath = My.Application.Info.DirectoryPath & "\Logs\"                 End If                  '[...]                  _MaxRollBacks = My.Settings.MaxRollBacks                 _MaxFileSize = My.Settings.MaxFileSize                  _isAppendToFile = My.Settings.isAppendToFile                 _isStaticLogFile = My.Settings.isStaticLogFile         End Sub          Private Sub configLog4Net()                 log4net.GlobalContext.Properties("LogPath") = _LogPath                 log4net.GlobalContext.Properties("LogName") = _LogName                 log4net.GlobalContext.Properties("RollStyle") = _tempRollStyle                 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks                 log4net.GlobalContext.Properties("MaxFileSize") = _MaxFileSize                 log4net.GlobalContext.Properties("isAppendToFile") = _isAppendToFile                 log4net.GlobalContext.Properties("isStaticLogFile") = _isStaticLogFile                 'My attempts to cast as a boolean (did not work)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isAppendToFile"), _isAppendToFile)                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isStaticLogFile"), _isStaticLogFile)         End Sub 'In Log4Net.config (using a seperate configuration file for Log4Net)<?xml version="1.0" encoding="utf-8" ?><configuration>         <configSections>                 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />         </configSections>         <appSettings>                 <!-- To enable internal log4net logging specify the following appSettings key -->                 <add key="log4net.Internal.Debug" value="true"/>         </appSettings>         <!-- This section contains the log4net configuration settings -->         <log4net>                 <!-- Define some output appenders -->                 <appender name="SyncLogFile" type="log4net.Appender.RollingFileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Syncronizations\%property{LogName}" />                          <param name="DatePattern" value=".yyyy-MM-dd-tt.log"/>                          <appendToFile value="%property{isAppendToFile}" />                          <maxSizeRollBackups type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />                          <maximumFileSize type="log4net.Util.PatternString" value="%property{MaxFileSize}" />                          <rollingStyle type="log4net.Util.PatternString" value="%property{RollStyle}" />                          <staticLogFileName value="%property{isStaticLogFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />                          </layout>                 </appender>                 <appender name="ErrLogFile" type="log4net.Appender.FileAppender">                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Errors\errLog.txt" />                          <sppendToFile value="%property{isAppendToFile}" />                          <layout type="log4net.Layout.PatternLayout">                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <appender name="EventLog" type="log4net.Appender.EventLogAppender">                          <layout type="log4net.Layout.PatternLayout">                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />                          </layout>                 </appender>                 <!-- Setup the root category, add the appenders and set the default level -->                 <root>                          <level value="ALL" />                          <appender-ref ref="SyncLogFile" />                          <appender-ref ref="ErrLogFile" />                          <appender-ref ref="ConsoleLog" />                          <appender-ref ref="EventLog" />                 </root>         </log4net></configuration>


All of my other appenders work (ConsoleLog, EventLog and ErrLogFile (when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-
Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.
_________________________________________________________________

MSN straight to your mobile - news, entertainment, videos and more.

http://clk.atdmt.com/UKM/go/147991039/direct/01/

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
Thanks Ron,

 

I started toying around with this type of method yesterday myself.  I
just couldn't come to grips with the final manifestation (was about to
start writing my own DynamicPattern class).  I'll give this a try and
let you know.

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: Monday, June 08, 2009 11:50 PM
To: Log4NET User
Subject: Re: How do I use dynamic boolean values on RollingFileAppender

 

This had me stumped for a while. My initial thought was to subclass
FileAppender or RollingFileAppender and override ActivateOptions. You
can't do that because the error happens during the XML configuration
processing. What you need to do is write a PatternString to Boolean
adapter for the XML processor:

public class PatternStringToBooleanAdapter : IConvertTo
{
    public string ConversionPattern { get; set; }

    public bool CanConvertTo(Type targetType)
    {
        return targetType == typeof(bool);
    }

    public object ConvertTo(object source, Type targetType)
    {
        var patternStringToBooleanAdapter =
(PatternStringToBooleanAdapter)source;

        var patternString = new
PatternString(patternStringToBooleanAdapter.ConversionPattern);

        string value = patternString.Format();

        return OptionConverter.ToBoolean(value, false);
    }
}

Register it before you process the xml file:

ConverterRegistry.AddConverter(typeof(PatternStringToBooleanAdapter),
new PatternStringToBooleanAdapter());
GlobalContext.Properties["AppendToFile"] = true;
log4net.Config.XmlConfigurator.Configure();

Then tell the XML processor that you want to intercept the normal
property setting with your adapter:

<appender name="FileAppender" type="log4net.Appender.FileAppender">
  <file value="log.txt" />
  <appendToFile type="ConsoleApplication1.PatternStringToBooleanAdapter,
ConsoleApplication1">
    <conversionPattern value="%property{AppendToFile}" />
  </appendToFile>
  <layout type="log4net.Layout.SimpleLayout" />
</appender>

 

________________________________

From: Richard Fouts <rf...@we-are-it.com>
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Sent: Friday, June 5, 2009 11:01:18 AM
Subject: How do I use dynamic boolean values on RollingFileAppender

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                
 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End
 Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                
 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug"
 value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                         
 </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
 value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.



Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

Re: How do I use dynamic boolean values on RollingFileAppender

Posted by Ron Grabowski <ro...@yahoo.com>.
The built-in PatternStringConverter takes a conversion pattern and converts it into a string. Here's a PatternObjectConverter that takes an conversion pattern and returns the appropriate typed object. This can replace your PatternStringToBooleanAdapter and PatternStringToInt32Adapter classes. It works by taking the string returned by the internal PatternString.Format call and using reflection to invoke the Type's Parse method on it. This means it will also work on DateTime, Decimal, etc. values without having to write special classes for those:

public class PatternObjectConverter : IConvertTo
{
    public string ConversionPattern { get; set; }

    public bool CanConvertTo(Type targetType)
    {
        // TODO: ensure Type has a Parse method on it
        return true; 
    }

    public object ConvertTo(object source, Type targetType)
    {
        var patternObjectConverter = (PatternObjectConverter)source;

        var patternString = new PatternString(patternObjectConverter.ConversionPattern);

        string value = patternString.Format();

        return OptionConverter.ConvertStringTo(targetType, value);
    }
}

log4net uses OptionConverter.ConvertStringTo internally to magically convert strings to typed objects when it parses the xml file. That's how it converts "true" to true.

There's a special case in OptionConverter.ConvertStringTo for enums so you shouldn't need PatternStringToRollingModeAdapter either :-)




________________________________
From: Richard Fouts <rf...@we-are-it.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Tuesday, June 9, 2009 3:24:45 PM
Subject: RE: How do I use dynamic boolean values on RollingFileAppender

 
Ron that worked beautifully. 
In case anyone else runs across this issue or something similar, I built a
couple of other Adapters based on the same model.  Here are all of the
adapters in all their glory.
 
‘In class AdditionalPatternStringAdapters
#Region "Boolean Pattern String"
PublicClass PatternStringToBooleanAdapter
      Implements TypeConverters.IConvertTo
 
      Private _ConversionPattern As String
 
      Public Property ConversionPattern() As String
            Get
                  Return _ConversionPattern
            End Get
            Set(ByVal value As String)
                  _ConversionPattern
= value
            End Set
      End Property
 
      Public Function CanConvertTo(ByVal targetType As Type) As Boolean Implements TypeConverters.IConvertTo.CanConvertTo
            Console.WriteLine("Taget Type is: " &
targetType.ToString & _
             " | Cast Type is: " & GetType(Boolean).ToString
& " | CASTABLE: " &
(targetType Is GetType(Int32)).ToString)
            Return targetType Is GetType(Boolean)
      End Function
 
      Public Function ConvertTo(ByVal source As Object, ByVal targetType As Type) As Object Implements TypeConverters.IConvertTo.ConvertTo
            Dim patternStringToBooleanAdapter = DirectCast(source, PatternStringToBooleanAdapter)
 
            Dim patternString = New PatternString(patternStringToBooleanAdapter.ConversionPattern)
 
            Dim value As String = patternString.Format()
 
            Return OptionConverter.ToBoolean(value, False)
      End Function
 
EndClass
#End Region
 
#Region "Int32 Pattern String"
PublicClass PatternStringToInt32Adapter
      Implements TypeConverters.IConvertTo
 
      Private _ConversionPattern As String
 
      Public Property ConversionPattern() As String
            Get
                  Return _ConversionPattern
            End Get
            Set(ByVal value As String)
                  _ConversionPattern
= value
            End Set
      End Property
 
      Public Function CanConvertTo(ByVal targetType As Type) As Boolean Implements TypeConverters.IConvertTo.CanConvertTo
            Console.WriteLine("Taget Type is: " &
targetType.ToString & _
             " | Cast Type is: " & GetType(Int32).ToString & " | CASTABLE: " & (targetType Is GetType(Int32)).ToString)
            Return targetType Is GetType(Int32)
      End Function
 
      Public Function ConvertTo(ByVal source As Object, ByVal targetType As Type) As Object Implements TypeConverters.IConvertTo.ConvertTo
            Dim patternStringToInt32Adapter = DirectCast(source, PatternStringToInt32Adapter)
 
            Dim patternString = New PatternString(PatternStringToInt32Adapter.ConversionPattern)
 
            Dim value As String = patternString.Format()
 
            If value IsNot Nothing AndAlso value.Length > 0 Then
                  Try
                        Return Int32.Parse(value)
                  Catch e As Exception
                        Console.WriteLine("AdditionalPatternStrings.PatternStringToInt32Adapter:
[" & value & "] is not in
proper Int32 form.", e)
                        value
= 8
                  End Try
            Else
                  value
= 8
            End If
 
            Return value
      End Function
 
EndClass
#End Region
 
#Region "Rolling Mode Pattern String"
PublicClass PatternStringToRollingModeAdapter
      Implements TypeConverters.IConvertTo
 
      Private _ConversionPattern As String
 
      Public Property ConversionPattern() As String
            Get
                  Return _ConversionPattern
            End Get
            Set(ByVal value As String)
                  _ConversionPattern
= value
            End Set
      End Property
 
      Public Function CanConvertTo(ByVal targetType As Type) As Boolean Implements TypeConverters.IConvertTo.CanConvertTo
            Console.WriteLine("Taget Type is: " &
targetType.ToString & _
             " | Cast Type is: " & GetType(log4net.Appender.RollingFileAppender.RollingMode).ToString
& " | CASTABLE: " &
(targetType Is GetType(log4net.Appender.RollingFileAppender.RollingMode)).ToString)
            Return targetType Is GetType(log4net.Appender.RollingFileAppender.RollingMode)
      End Function
 
      Public Function ConvertTo(ByVal source As Object, ByVal targetType As Type) As Object Implements TypeConverters.IConvertTo.ConvertTo
            Dim patternStringToRollingModeAdapter = DirectCast(source, PatternStringToRollingModeAdapter)
 
            Dim patternString = New PatternString(patternStringToRollingModeAdapter.ConversionPattern)
 
            Dim value As String = patternString.Format()
            Console.WriteLine("AdditionalPatternStrings.PatternStringRollingModeAdapter:
[" & value & "] is the
asking to be converted.")
 
            If value IsNot Nothing AndAlso value.Length > 0 Then
                  Try
                        Select Case value
                              Case "Composite"
                                    Return log4net.Appender.RollingFileAppender.RollingMode.Composite
                              Case "Once"
                                    Return log4net.Appender.RollingFileAppender.RollingMode.Composite
                        End Select
                  Catch e As Exception
                        Console.WriteLine("AdditionalPatternStrings.PatternStringToRollingModeAdapter:
[" & value & "] is not in
proper Rolling Mode form.", e)
                        value
= log4net.Appender.RollingFileAppender.RollingMode.Composite
                  End Try
            Else
                  value
= log4net.Appender.RollingFileAppender.RollingMode.Composite
            End If
 
            Return log4net.Appender.RollingFileAppender.RollingMode.Composite
      End Function
 
EndClass
#End Region
 
‘In Main
            log4net.Util.TypeConverters.ConverterRegistry.AddConverter(GetType(PatternStringToBooleanAdapter), New PatternStringToBooleanAdapter())
            log4net.Util.TypeConverters.ConverterRegistry.AddConverter(GetType(PatternStringToInt32Adapter), New PatternStringToInt32Adapter())
            log4net.Util.TypeConverters.ConverterRegistry.AddConverter(GetType(PatternStringToRollingModeAdapter), New PatternStringToRollingModeAdapter())
 
‘In Configuration File
            <appendername="SyncLogFile"type="log4net.Appender.RollingFileAppender">
                  <filetype="log4net.Util.PatternString"value="%property{LogPath}\Synchronizations\%property{LogName}"/>
                  <datePatternvalue="yyyy-MM-dd'.log'"/>
                  <appendToFiletype="FileSync.PatternStringToBooleanAdapter, FileSync">
                        <conversionPatternvalue="%property{isAppendToFile}"/>
                  </appendToFile>
                  <maxSizeRollBackupstype="FileSync.PatternStringToInt32Adapter, FileSync">
                        <conversionPatternvalue="%property{MaxRollBacks}"/>
                  </maxSizeRollBackups>
                  <maximumFileSizetype="log4net.Util.PatternString"value="%property{MaxFileSize}"/>
                  <staticLogFileNametype="FileSync.PatternStringToBooleanAdapter, FileSync">
                        <conversionPatternvalue="%property{isStaticLogFile}"/>
                  </staticLogFileName>
                  <rollingStyletype="FileSync.PatternStringToRollingModeAdapter, FileSync">
                        <conversionPatternvalue="%property{RollStyle}"/>
                  </rollingStyle>
                  <layouttype="log4net.Layout.PatternLayout">
                        <headertype="log4net.Util.PatternString"value="****************************************
Logging Started - %date ******************************************&#13;&#10;"/>
                        <footertype="log4net.Util.PatternString"value="****************************************
Logging Ended - %date ******************************************&#13;&#10;"/>
                        <conversionPatternvalue="%date [%thread] %-5level %logger [%ndc] - %message%newline"/>
                  </layout>
            </appender>

RE: How do I use dynamic boolean values on RollingFileAppender

Posted by Richard Fouts <rf...@we-are-it.com>.
Ron that worked beautifully.  In case anyone else runs across this issue
or something similar, I built a couple of other Adapters based on the
same model.  Here are all of the adapters in all their glory.

 

'In class AdditionalPatternStringAdapters

#Region "Boolean Pattern String"

Public Class PatternStringToBooleanAdapter

      Implements TypeConverters.IConvertTo

 

      Private _ConversionPattern As String

 

      Public Property ConversionPattern() As String

            Get

                  Return _ConversionPattern

            End Get

            Set(ByVal value As String)

                  _ConversionPattern = value

            End Set

      End Property

 

      Public Function CanConvertTo(ByVal targetType As Type) As Boolean
Implements TypeConverters.IConvertTo.CanConvertTo

            Console.WriteLine("Taget Type is: " & targetType.ToString &
_

             " | Cast Type is: " & GetType(Boolean).ToString & " |
CASTABLE: " & (targetType Is GetType(Int32)).ToString)

            Return targetType Is GetType(Boolean)

      End Function

 

      Public Function ConvertTo(ByVal source As Object, ByVal targetType
As Type) As Object Implements TypeConverters.IConvertTo.ConvertTo

            Dim patternStringToBooleanAdapter = DirectCast(source,
PatternStringToBooleanAdapter)

 

            Dim patternString = New
PatternString(patternStringToBooleanAdapter.ConversionPattern)

 

            Dim value As String = patternString.Format()

 

            Return OptionConverter.ToBoolean(value, False)

      End Function

 

End Class

#End Region

 

#Region "Int32 Pattern String"

Public Class PatternStringToInt32Adapter

      Implements TypeConverters.IConvertTo

 

      Private _ConversionPattern As String

 

      Public Property ConversionPattern() As String

            Get

                  Return _ConversionPattern

            End Get

            Set(ByVal value As String)

                  _ConversionPattern = value

            End Set

      End Property

 

      Public Function CanConvertTo(ByVal targetType As Type) As Boolean
Implements TypeConverters.IConvertTo.CanConvertTo

            Console.WriteLine("Taget Type is: " & targetType.ToString &
_

             " | Cast Type is: " & GetType(Int32).ToString & " |
CASTABLE: " & (targetType Is GetType(Int32)).ToString)

            Return targetType Is GetType(Int32)

      End Function

 

      Public Function ConvertTo(ByVal source As Object, ByVal targetType
As Type) As Object Implements TypeConverters.IConvertTo.ConvertTo

            Dim patternStringToInt32Adapter = DirectCast(source,
PatternStringToInt32Adapter)

 

            Dim patternString = New
PatternString(PatternStringToInt32Adapter.ConversionPattern)

 

            Dim value As String = patternString.Format()

 

            If value IsNot Nothing AndAlso value.Length > 0 Then

                  Try

                        Return Int32.Parse(value)

                  Catch e As Exception

 
Console.WriteLine("AdditionalPatternStrings.PatternStringToInt32Adapter:
[" & value & "] is not in proper Int32 form.", e)

                        value = 8

                  End Try

            Else

                  value = 8

            End If

 

            Return value

      End Function

 

End Class

#End Region

 

#Region "Rolling Mode Pattern String"

Public Class PatternStringToRollingModeAdapter

      Implements TypeConverters.IConvertTo

 

      Private _ConversionPattern As String

 

      Public Property ConversionPattern() As String

            Get

                  Return _ConversionPattern

            End Get

            Set(ByVal value As String)

                  _ConversionPattern = value

            End Set

      End Property

 

      Public Function CanConvertTo(ByVal targetType As Type) As Boolean
Implements TypeConverters.IConvertTo.CanConvertTo

            Console.WriteLine("Taget Type is: " & targetType.ToString &
_

             " | Cast Type is: " &
GetType(log4net.Appender.RollingFileAppender.RollingMode).ToString & " |
CASTABLE: " & (targetType Is
GetType(log4net.Appender.RollingFileAppender.RollingMode)).ToString)

            Return targetType Is
GetType(log4net.Appender.RollingFileAppender.RollingMode)

      End Function

 

      Public Function ConvertTo(ByVal source As Object, ByVal targetType
As Type) As Object Implements TypeConverters.IConvertTo.ConvertTo

            Dim patternStringToRollingModeAdapter = DirectCast(source,
PatternStringToRollingModeAdapter)

 

            Dim patternString = New
PatternString(patternStringToRollingModeAdapter.ConversionPattern)

 

            Dim value As String = patternString.Format()

 
Console.WriteLine("AdditionalPatternStrings.PatternStringRollingModeAdap
ter: [" & value & "] is the asking to be converted.")

 

            If value IsNot Nothing AndAlso value.Length > 0 Then

                  Try

                        Select Case value

                              Case "Composite"

                                    Return
log4net.Appender.RollingFileAppender.RollingMode.Composite

                              Case "Once"

                                    Return
log4net.Appender.RollingFileAppender.RollingMode.Composite

                        End Select

                  Catch e As Exception

 
Console.WriteLine("AdditionalPatternStrings.PatternStringToRollingModeAd
apter: [" & value & "] is not in proper Rolling Mode form.", e)

                        value =
log4net.Appender.RollingFileAppender.RollingMode.Composite

                  End Try

            Else

                  value =
log4net.Appender.RollingFileAppender.RollingMode.Composite

            End If

 

            Return
log4net.Appender.RollingFileAppender.RollingMode.Composite

      End Function

 

End Class

#End Region

 

'In Main

 
log4net.Util.TypeConverters.ConverterRegistry.AddConverter(GetType(Patte
rnStringToBooleanAdapter), New PatternStringToBooleanAdapter())

 
log4net.Util.TypeConverters.ConverterRegistry.AddConverter(GetType(Patte
rnStringToInt32Adapter), New PatternStringToInt32Adapter())

 
log4net.Util.TypeConverters.ConverterRegistry.AddConverter(GetType(Patte
rnStringToRollingModeAdapter), New PatternStringToRollingModeAdapter())

 

'In Configuration File

            <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">

                  <file type="log4net.Util.PatternString"
value="%property{LogPath}\Synchronizations\%property{LogName}" />

                  <datePattern value="yyyy-MM-dd'.log'"/>

                  <appendToFile
type="FileSync.PatternStringToBooleanAdapter, FileSync">

                        <conversionPattern
value="%property{isAppendToFile}" />

                  </appendToFile >

                  <maxSizeRollBackups
type="FileSync.PatternStringToInt32Adapter, FileSync">

                        <conversionPattern
value="%property{MaxRollBacks}" />

                  </maxSizeRollBackups >

                  <maximumFileSize type="log4net.Util.PatternString"
value="%property{MaxFileSize}" />

                  <staticLogFileName
type="FileSync.PatternStringToBooleanAdapter, FileSync">

                        <conversionPattern
value="%property{isStaticLogFile}" />

                  </staticLogFileName>

                  <rollingStyle
type="FileSync.PatternStringToRollingModeAdapter, FileSync">

                        <conversionPattern value="%property{RollStyle}"
/>

                  </rollingStyle>

                  <layout type="log4net.Layout.PatternLayout">

                        <header type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />

                        <footer type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />

                        <conversionPattern value="%date [%thread]
%-5level %logger [%ndc] - %message%newline" />

                  </layout>

            </appender>

 

-Richard Fouts

 

Senior OS/Network Specialist

We Are IT

11040 Holmes Road

Kansas City, MO  64131

Phone: (816) 941-6800

Fax: (816) 941-4420

 

http://www.we-are-it.com/

From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: Monday, June 08, 2009 11:50 PM
To: Log4NET User
Subject: Re: How do I use dynamic boolean values on RollingFileAppender

 

This had me stumped for a while. My initial thought was to subclass
FileAppender or RollingFileAppender and override ActivateOptions. You
can't do that because the error happens during the XML configuration
processing. What you need to do is write a PatternString to Boolean
adapter for the XML processor:

public class PatternStringToBooleanAdapter : IConvertTo
{
    public string ConversionPattern { get; set; }

    public bool CanConvertTo(Type targetType)
    {
        return targetType == typeof(bool);
    }

    public object ConvertTo(object source, Type targetType)
    {
        var patternStringToBooleanAdapter =
(PatternStringToBooleanAdapter)source;

        var patternString = new
PatternString(patternStringToBooleanAdapter.ConversionPattern);

        string value = patternString.Format();

        return OptionConverter.ToBoolean(value, false);
    }
}

Register it before you process the xml file:

ConverterRegistry.AddConverter(typeof(PatternStringToBooleanAdapter),
new PatternStringToBooleanAdapter());
GlobalContext.Properties["AppendToFile"] = true;
log4net.Config.XmlConfigurator.Configure();

Then tell the XML processor that you want to intercept the normal
property setting with your adapter:

<appender name="FileAppender" type="log4net.Appender.FileAppender">
  <file value="log.txt" />
  <appendToFile type="ConsoleApplication1.PatternStringToBooleanAdapter,
ConsoleApplication1">
    <conversionPattern value="%property{AppendToFile}" />
  </appendToFile>
  <layout type="log4net.Layout.SimpleLayout" />
</appender>

 

________________________________

From: Richard Fouts <rf...@we-are-it.com>
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Sent: Friday, June 5, 2009 11:01:18 AM
Subject: How do I use dynamic boolean values on RollingFileAppender

I have ran into a "small" brick wall.  Hoping that I can find a couple
of log4net guru's here.  My situation.

In trying to make my logging as configurable as possible in my
application, I have been tinkering with trying to set the boolean values
for appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My
problem is that when I go to configure the values at runtime I get this
error in my stack trace:

 

 

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [SyncLogFile] not
found.
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type target, String
txt)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Ty
pe type, String value)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlEl
ement element, Object target)
   at
log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE
lement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [ErrLogFile] not
found.

The way that I am configuring the values is by trying to use the code
displayed here:

 

	
'In Main
         Private Shared Log As ILog
 
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Dec
laringType)
                 Log.Info("This is the start of the application.")
         End Sub
 
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath &
"\Logs\"
                 End If
 
                
 '[...]
 
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
 
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End
 Sub
 
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") =
_tempRollStyle
                
 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") =
_MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") =
_isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") =
_isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isAppendToFile"), _isAppendToFile)
 
'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties
("isStaticLogFile"), _isStaticLogFile)
         End Sub
 
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the
following appSettings key -->
                 <add key="log4net.Internal.Debug"
 value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings
-->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile"
type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern"
value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile
value="%property{isAppendToFile}" />
                          <maxSizeRollBackups
type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize
type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle
type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName
value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] - %message%newline" />
                         
 </layout>
                 </appender>
                 <appender name="ErrLogFile"
type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString"
value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile
value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header
type="log4net.Util.PatternString"
value="**************************************** Logging Started - %date
******************************************&#13;&#10;" />
                                   <footer
type="log4net.Util.PatternString"
 value="**************************************** Logging Ended - %date
******************************************&#13;&#10;" />
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog"
type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog"
type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date
[%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; -
%message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set
the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>



All of my other appenders work (ConsoleLog, EventLog and ErrLogFile
(when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

 
Do you have a disaster recovery plan for your servers? If not, ask about
We Are 
IT's Total Rescue business continuity plan.



Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.

Re: How do I use dynamic boolean values on RollingFileAppender

Posted by Ron Grabowski <ro...@yahoo.com>.
This had me stumped for a while. My initial thought was to subclass FileAppender or RollingFileAppender and override ActivateOptions. You can't do that because the error happens during the XML configuration processing. What you need to do is write a PatternString to Boolean adapter for the XML processor:

public class PatternStringToBooleanAdapter : IConvertTo
{
    public string ConversionPattern { get; set; }

    public bool CanConvertTo(Type targetType)
    {
        return targetType == typeof(bool);
    }

    public object ConvertTo(object source, Type targetType)
    {
        var patternStringToBooleanAdapter = (PatternStringToBooleanAdapter)source;

        var patternString = new PatternString(patternStringToBooleanAdapter.ConversionPattern);

        string value = patternString.Format();

        return OptionConverter.ToBoolean(value, false);
    }
}

Register it before you process the xml file:

ConverterRegistry.AddConverter(typeof(PatternStringToBooleanAdapter), new PatternStringToBooleanAdapter());
GlobalContext.Properties["AppendToFile"] = true;
log4net.Config.XmlConfigurator.Configure();

Then tell the XML processor that you want to intercept the normal property setting with your adapter:

<appender name="FileAppender" type="log4net.Appender.FileAppender">
  <file value="log.txt" />
  <appendToFile type="ConsoleApplication1.PatternStringToBooleanAdapter, ConsoleApplication1">
    <conversionPattern value="%property{AppendToFile}" />
  </appendToFile>
  <layout type="log4net.Layout.SimpleLayout" />
</appender>




________________________________
From: Richard Fouts <rf...@we-are-it.com>
To: log4net-user@logging.apache.org; log4net-dev@logging.apache.org
Sent: Friday, June 5, 2009 11:01:18 AM
Subject: How do I use dynamic boolean values on RollingFileAppender

 
I have ran into a "small" brick wall.
 Hoping that I can find a couple of log4net guru's here.  My
situation.

In trying to make my logging as configurable as possible in
my application, I have been tinkering with trying to set the boolean values for
appendToFile and staticLogFileName as dynamic values.  These have a
default value (currently stored in the My.Settings metadata).  My problem
is that when I go to configure the values at runtime I get this error in my
stack trace:
 
 
log4net:ERROR XmlHierarchyConfigurator: Could not
create Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender].
Reported error follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[ErrLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [SyncLogFile] of type [log4net.Appender.RollingFileAppender]. Reported
error follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[SyncLogFile] not found.
log4net:ERROR XmlHierarchyConfigurator: Could not create
Appender [ErrLogFile] of type [log4net.Appender.FileAppender]. Reported error
follows.
System.FormatException: String was not recognized as a valid
Boolean.
   at System.Boolean.Parse(String value)
   at log4net.Util.TypeConverters.BooleanConverter.ConvertFrom(Object
source)
   at log4net.Util.OptionConverter.ConvertStringTo(Type
target, String txt)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type
type, String value)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement
element, Object target)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement
appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named
[ErrLogFile] not found.

The way that I am configuring the values is by trying to use
the code displayed here:
 
 
'In Main
         Private Shared Log As ILog
         Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                 '[...]
                 primeLogging()
                 configLog4Net()
                 Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
                 Log.Info("This is the start of the application.")
         End Sub
         Private Sub primeLogging()
                 If Not My.Settings.LogPath = "" Then
                          _LogPath = My.Settings.LogPath
                 Else
                          _LogPath = My.Application.Info.DirectoryPath & "\Logs\"
                 End If
                 '[...]
                 _MaxRollBacks = My.Settings.MaxRollBacks
                 _MaxFileSize = My.Settings.MaxFileSize
                 _isAppendToFile = My.Settings.isAppendToFile
                 _isStaticLogFile = My.Settings.isStaticLogFile
         End Sub
         Private Sub configLog4Net()
                 log4net.GlobalContext.Properties("LogPath") = _LogPath
                 log4net.GlobalContext.Properties("LogName") = _LogName
                 log4net.GlobalContext.Properties("RollStyle") = _tempRollStyle
                 log4net.GlobalContext.Properties("MaxRollBacks") = _MaxRollBacks
                 log4net.GlobalContext.Properties("MaxFileSize") = _MaxFileSize
                 log4net.GlobalContext.Properties("isAppendToFile") = _isAppendToFile
                 log4net.GlobalContext.Properties("isStaticLogFile") = _isStaticLogFile
                 'My attempts to cast as a boolean (did not work)
                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isAppendToFile"), _isAppendToFile)
                  'log4net.Util.OptionConverter.ToBoolean(log4net.GlobalContext.Properties("isStaticLogFile"), _isStaticLogFile)
         End Sub
'In Log4Net.config (using a seperate configuration file for Log4Net)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
         <configSections>
                 <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
         </configSections>
         <appSettings>
                 <!-- To enable internal log4net logging specify the following appSettings key -->
                 <add key="log4net.Internal.Debug" value="true"/>
         </appSettings>
         <!-- This section contains the log4net configuration settings -->
         <log4net>
                 <!-- Define some output appenders -->
                 <appender name="SyncLogFile" type="log4net.Appender.RollingFileAppender">
                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Syncronizations\%property{LogName}" />
                          <param name="DatePattern" value=".yyyy-MM-dd-tt.log"/>
                          <appendToFile value="%property{isAppendToFile}" />
                          <maxSizeRollBackups type="log4net.Util.PatternString" value="%property{MaxRollBacks}" />
                          <maximumFileSize type="log4net.Util.PatternString" value="%property{MaxFileSize}" />
                          <rollingStyle type="log4net.Util.PatternString" value="%property{RollStyle}" />
                          <staticLogFileName value="%property{isStaticLogFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />
                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ErrLogFile" type="log4net.Appender.FileAppender">
                          <file type="log4net.Util.PatternString" value="%property{LogPath}\Errors\errLog.txt" />
                          <sppendToFile value="%property{isAppendToFile}" />
                          <layout type="log4net.Layout.PatternLayout">
                                   <header type="log4net.Util.PatternString" value="**************************************** Logging Started - %date ******************************************&#13;&#10;" />
                                   <footer type="log4net.Util.PatternString" value="**************************************** Logging Ended - %date ******************************************&#13;&#10;" />
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <appender name="EventLog" type="log4net.Appender.EventLogAppender">
                          <layout type="log4net.Layout.PatternLayout">
                                   <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
                          </layout>
                 </appender>
                 <!-- Setup the root category, add the appenders and set the default level -->
                 <root>
                          <level value="ALL" />
                          <appender-ref ref="SyncLogFile" />
                          <appender-ref ref="ErrLogFile" />
                          <appender-ref ref="ConsoleLog" />
                          <appender-ref ref="EventLog" />
                 </root>
         </log4net>
</configuration>


All of my other appenders work (ConsoleLog, EventLog and
ErrLogFile (when I remove the appendToFile paramter).

Please any assistance would be most appreciated.

Thanks,

-saige-

Do you have a disaster recovery plan for your servers? If not, ask about We Are 
IT's Total Rescue business continuity plan.