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 karlkras <ka...@yahoo.com> on 2015/04/09 19:17:39 UTC

Can't get RollingFileAppender to work...

Hello again. So I'm trying to configure a RollingFileAppender logger to work
against a custom level. However, when I call the custom level no file with
content is created/produced.
The xml configuration looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
requirePermission="false" />
	</configSections>
	<log4net debug="True">
		<level>
			<name value="AUDIT" />
			<value value="80000" />
		</level>
		<root>
			<appender-ref ref="LogglyLogger" >
				<threshold value="DEBUG" />
			</appender-ref>
		</root>
		<logger name="EventLogger" additivity="False">
			<level value="ERROR"/>
		</logger>
		<logger name="RollingFile" additivity="False">
			<level value="AUDIT"/>
		</logger>
		
		<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
			<file value="c:\logs\connector\Connector.log" />
			<appendToFile value="true" />
			<datePattern value="yyyyMMdd" />
			<rollingStyle value="Date" />
			<maxSizeRollBackups value="30"/>
			<staticLogFileName value="true" />
			<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%-5p %d [%thread] %5rms %-22.22c{1} %-18.18M -
%m%n" />
			</layout>
		</appender>

...

the C# code looks like this:

public class MyLogger
{
		static readonly log4net.Core.Level auditLevel = new
log4net.Core.Level(80000, "Audit");
                private static ILog _logger;

                public void MyLogger()
                {
			string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"Config\\Logging.config");
			FileInfo finfo = new FileInfo(logFilePath);
			log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");
			log4net.LogManager.GetRepository().LevelMap.Add(auditLevel);
			log4net.Config.XmlConfigurator.ConfigureAndWatch(finfo);
			_logger = LogManager.GetLogger(typeof(WAConnectorLogger));
                }

		public void Audit(string message)
		{
		
_logger.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
				auditLevel, message, null);
		}


but when I call this method, no log is produced. Any ideas what I'm doing
wrong here?
It all appears to proceed without error so I'm assuming something in my
configuration isn't quite right.
Other appenders are working as hoped, so there's no problem loading the
log4net xml file.

thanks!
            






--
View this message in context: http://apache-logging.6191.n7.nabble.com/Can-t-get-RollingFileAppender-to-work-tp54533.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

RE: Can't get RollingFileAppender to work...

Posted by Neil Haughton <Ne...@autoscribe.co.uk>.
Case, perhaps?

	<level>
	      <name value="AUDIT" />
                     ...
	</level>


		static readonly log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");


ie "AUDIT", "Audit" are not the same case.


Best Regards,

Neil Haughton BSc MIET IEng(CEI)
Development Manager

   

Autoscribe Limited
Wellington House,
Riseley Business Park
Basingstoke Road, Riseley
Berkshire RG7 1NW
Office:   +44 (0) 118 984 0610
Fax:      +44 (0) 118 984 0611
Email:  neil.haughton@autoscribe.co.uk    Visit our website at: www.autoscribeinformatics.com
Registered in Wales No. 1539748




**********************************************************DISCLAIMER*****************************************************

The contents of this email are confidential and are intended solely for the use of the individual or company to
whom it is addressed. If you have received this email in error then please accept our apology. If this is the case
we would be obliged if you would contact the sender and then delete this email. Opinions expressed in this email
are those of the individual and do not necessarily represent the opinions of Autoscribe Ltd. Although this email
and any attachments are believed to be free of any virus no responsibility is accepted by Autoscribe Ltd for any
loss or damage arising in any way from the receipt or use of this email or attachments.



-----Original Message-----
From: karlkras [mailto:karlkras@yahoo.com] 
Sent: 09 April 2015 18:18
To: log4net-user@logging.apache.org
Subject: Can't get RollingFileAppender to work...

Hello again. So I'm trying to configure a RollingFileAppender logger to work against a custom level. However, when I call the custom level no file with content is created/produced.
The xml configuration looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
requirePermission="false" />
	</configSections>
	<log4net debug="True">
		<level>
			<name value="AUDIT" />
			<value value="80000" />
		</level>
		<root>
			<appender-ref ref="LogglyLogger" >
				<threshold value="DEBUG" />
			</appender-ref>
		</root>
		<logger name="EventLogger" additivity="False">
			<level value="ERROR"/>
		</logger>
		<logger name="RollingFile" additivity="False">
			<level value="AUDIT"/>
		</logger>
		
		<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
			<file value="c:\logs\connector\Connector.log" />
			<appendToFile value="true" />
			<datePattern value="yyyyMMdd" />
			<rollingStyle value="Date" />
			<maxSizeRollBackups value="30"/>
			<staticLogFileName value="true" />
			<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%-5p %d [%thread] %5rms %-22.22c{1} %-18.18M - %m%n" />
			</layout>
		</appender>

...

the C# code looks like this:

public class MyLogger
{
		static readonly log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");
                private static ILog _logger;

                public void MyLogger()
                {
			string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"Config\\Logging.config");
			FileInfo finfo = new FileInfo(logFilePath);
			log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");
			log4net.LogManager.GetRepository().LevelMap.Add(auditLevel);
			log4net.Config.XmlConfigurator.ConfigureAndWatch(finfo);
			_logger = LogManager.GetLogger(typeof(WAConnectorLogger));
                }

		public void Audit(string message)
		{
		
_logger.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
				auditLevel, message, null);
		}


but when I call this method, no log is produced. Any ideas what I'm doing wrong here?
It all appears to proceed without error so I'm assuming something in my configuration isn't quite right.
Other appenders are working as hoped, so there's no problem loading the log4net xml file.

thanks!
            






--
View this message in context: http://apache-logging.6191.n7.nabble.com/Can-t-get-RollingFileAppender-to-work-tp54533.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

RE: Can't get RollingFileAppender to work...

Posted by Radovan Raszka <ra...@hasam.cz>.
Hello.
First of all - you are trying to use nonexisting logger. You define:
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

Byt trying to use:
<root>
-->>>	<appender-ref ref="LogglyLogger" >
	    <threshold value="DEBUG" />
	</appender-ref>
</root>

Second - your example can't be compiled - remove void in public void MyLogger(), constructor has no return type
If you fix these two mistakes,  it should work.
Cheers, Radovan

-----Original Message-----
From: karlkras [mailto:karlkras@yahoo.com] 
Sent: Thursday, April 09, 2015 7:18 PM
To: log4net-user@logging.apache.org
Subject: Can't get RollingFileAppender to work...

Hello again. So I'm trying to configure a RollingFileAppender logger to work against a custom level. However, when I call the custom level no file with content is created/produced.
The xml configuration looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
requirePermission="false" />
	</configSections>
	<log4net debug="True">
		<level>
			<name value="AUDIT" />
			<value value="80000" />
		</level>
		<root>
			<appender-ref ref="LogglyLogger" >
				<threshold value="DEBUG" />
			</appender-ref>
		</root>
		<logger name="EventLogger" additivity="False">
			<level value="ERROR"/>
		</logger>
		<logger name="RollingFile" additivity="False">
			<level value="AUDIT"/>
		</logger>
		
		<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
			<file value="c:\logs\connector\Connector.log" />
			<appendToFile value="true" />
			<datePattern value="yyyyMMdd" />
			<rollingStyle value="Date" />
			<maxSizeRollBackups value="30"/>
			<staticLogFileName value="true" />
			<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%-5p %d [%thread] %5rms %-22.22c{1} %-18.18M - %m%n" />
			</layout>
		</appender>

...

the C# code looks like this:

public class MyLogger
{
		static readonly log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");
                private static ILog _logger;

                public void MyLogger()
                {
			string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"Config\\Logging.config");
			FileInfo finfo = new FileInfo(logFilePath);
			log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");
			log4net.LogManager.GetRepository().LevelMap.Add(auditLevel);
			log4net.Config.XmlConfigurator.ConfigureAndWatch(finfo);
			_logger = LogManager.GetLogger(typeof(WAConnectorLogger));
                }

		public void Audit(string message)
		{
		
_logger.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
				auditLevel, message, null);
		}


but when I call this method, no log is produced. Any ideas what I'm doing wrong here?
It all appears to proceed without error so I'm assuming something in my configuration isn't quite right.
Other appenders are working as hoped, so there's no problem loading the log4net xml file.

thanks!
            






--
View this message in context: http://apache-logging.6191.n7.nabble.com/Can-t-get-RollingFileAppender-to-work-tp54533.html
Sent from the Log4net - Users mailing list archive at Nabble.com.