Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am making console application and using log4Net for logging.
My "RollingLogFileAppender" appender in App.Config file is as follows:

XML
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
	<file type="log4net.Util.PatternString" value=".\MsgBoxlog.log" />   
	<appendtofile value="true" />   
	<rollingstyle value="Size" />   
	<maxsizerollbackups value="5" />   
	<maximumfilesize value="2MB" />   
	<staticlogfilename value="true" />   
	<layout type="log4net.Layout.PatternLayout">
	  <param name="Header" value="[BEGIN LOGGING AT %date]%newline" type="log4net.Util.PatternString" />
	  <param name="Footer" value="[END LOGGING AT %date]%newline" type="log4net.Util.PatternString" />
	  <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
	</layout>  
</appender>


But when I am executing application, I am getting the following error:

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [RollingLogFileAppender] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
System.ArgumentNullException: Value cannot be null.
Parameter name:fileName
    at System.IO.FileInfo..ctor(String fileName)
    at log4net.Appender.RollingFileAppender.CleanUpHistoryLogFiles()
    at log4net.Appender.RollingFileAppender.ActivateOption()
    at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:Error XmlHierarchyConfigurator: Appender named [RollingLogFileAppender] not found.
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
Posted
Updated 16-Mar-11 11:03am
v3
Comments
Wendelius 16-Mar-11 13:13pm    
Enhanced readability
Zia Mehdi 16-Mar-11 13:50pm    
Thanks Mike

Check this link out:

RollingFileAppender tips[^]

BTW, google is pretty handy...
 
Share this answer
 
Comments
Zia Mehdi 16-Mar-11 15:30pm    
I have googled this but it is the special condition.
Previously my "RollingLogFileAppender" was configured with RollingStyle="Date" and it was working fine. But when I change this with RollingStyle="Size" since then it is giving me error. Even if I change RollingStyle="Date" with the same other values it works fine agian. I don't know what is the problem with the SIZE rollingstyle.
fjdiewornncalwe 16-Mar-11 23:04pm    
Zia, you may be missing some configuration information in your application. Different types of appenders require different settings to be defined. I haven't read all of your code snippet so I can't offhand tell you what is missing if anything.
Zia Mehdi 17-Mar-11 11:28am    
Thanks Marcus.
I have changed all settings of RollingFileAppender for RollingStyle "Size". Even then it is saying RollingFileAppender not found. I guess it should atleast find the appender.
The argument fileName can't be null or an empty string. Look in your C# code. Try running your code under the debugger. It will stop at (or near) the point of failure.
 
Share this answer
 
v2
Comments
Zia Mehdi 16-Mar-11 13:54pm    
File is defined in App.Config file ".\MsgBoxlog.log".
Previously my "RollingLogFileAppender" was configured with RollingStyle="Date" and it was working fine. But when I change this with RollingStyle="Size" since then it is giving me error.
Even if I change RollingStyle="Date" with the same other values it works fine agian.
I don't know what is the problem with the SIZE rollingstyle.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900