log4net-dev

[Prev] Thread [Next]  |  [Prev] Date [Next]

How do I use dynamic boolean values on RollingFileAppender Richard Fouts Fri Jun 05 08:02:17 2009

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.