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 Ross Hinkley <ro...@gmail.com> on 2009/04/08 14:54:02 UTC
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
You can specify a threshold value in the appender. That would allow you to
log messages from a given level and higher. For example, as a child to the
appender node:
<threshold value="INFO">
would log Info messages, Warning messages, and so on. From there, you can
use Ron's suggestion for controlling what you want to see overall and to
manage multiple appenders.
If I understand your question, Omatase, it sounds like you want to log one
log level per file, maybe? I'm not certain you can specify an upper
threshold to an appender. I've never used log4net in such a fashion. Does
anyone know if you can set an upper limit on an appender?
Omatase, if you need a more complete example, let me know.
-Ross
On Tue, Apr 7, 2009 at 10:14 PM, Neil Haughton <
Neil.Haughton@autoscribe.co.uk> wrote:
>
> PMFBI but that would log to both appenders using the same level. Omatase
> seems to want to log to each appender using different levels to control
> each.
>
> Regards,
>
> Neil Haughton
>
>
> -----Original Message-----
> From: Ron Grabowski [mailto:rongrabowski@yahoo.com<ro...@yahoo.com>
> ]
> Sent: Wed 08/04/2009 00:09
> To: Log4NET User
> Subject: Re: Error destroying my productivity Please Help!: log4net:ERROR
> [] Attempted to append to closed appender named []
>
>
> Does this work?
>
> <logger name="Invoicing">
> <level value="DEBUG" />
> <appender-ref ref="AdoNetAppender" />
> <appender-ref ref="FileAppender" />
> </logger>
>
>
> ----- Original Message ----
> From: omatase <Om...@gmail.com>
> To: log4net-user@logging.apache.org
> Sent: Tuesday, April 7, 2009 6:17:29 PM
> Subject: Error destroying my productivity Please Help!: log4net:ERROR []
> Attempted to append to closed appender named []
>
>
> I cannot figure this one out.
>
> I have been tasked by my team to create a logging service so that we can
> all
> have convenient logging without having to integrate it into our individual
> projects. I decided to do this I would just build a wrapper around log4net
> that makes it even simpler to use than it already is.
>
> After not too much work I got it up and running and (seemingly) working. I
> had it running on a development web server here for people to begin using
> with no issues initially.
>
> Now I am getting this really really really crappy error whenever I try to
> write a log no matter the loglevel or the logger being used. I have
> narrowed
> it down to config file changes but cannot find an answer.
>
> The changes I narrowed it down to are:
> If I have the following configuration in my log4net xml section everything
> is fine
>
> <root>
> <level value="DEBUG" />
> <appender-ref ref="AdoNetAppender" />
> </root>
>
> And if I add an additional logger suchas:
>
> <logger name="Invoicing">
> <level value="DEBUG" />
> <appender-ref ref="AdoNetAppender" />
> </logger>
>
> we're still in good shape. But! When I add another logger with the same
> "name" as another existing logger suchas:
>
> <logger name="Invoicing">
> <level value="FATAL" />
> <appender-ref ref="FileAppender" />
> </logger>
>
> all hell breaks loose and I get the following error:
>
> "log4net:ERROR [] Attempted to append to closed appender named []"
>
> I am certain log4net is supposed to support a log strategy such as this so
> that I can have fatal messages logged differently for the same logger name.
> Can someone help me understand what's going on?
>
> I can post any and all code I have if it will help diagnose the problem.
>
> Thanks
> --
> View this message in context:
> http://www.nabble.com/Error-destroying-my-productivity-Please-Help%21%3A-log4net%3AERROR----Attempted-to-append-to-closed-appender-named----tp22939427p22939427.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>
>
>
>
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by Daniel Marohn <ma...@sipgate.de>.
Hallo again ...
I was not able to reproduce your problem. The config runs without
errors on my system.
But I had some time to study the log4net sources and can tell you,
that there is totaly no way to configure 2 Loggers with the same
name.
The reason: The Repository stores all Logers in a Hashtable; the
logger name is used as the key for this table, so it's impossible to
store two loggers with the same name. What happens in XmlConfig is
like this:
It loops through root xml elements. For every Logger element, it calls
getLogger(Name) to get the logger (wich will create a new logger or
return the allready created if exists). Level is set/overriden,
AppenderRefs are erased, and recreated.
In the end, your Logger is allways configured like the last definition
in configfile.
You can profe this very simple for yourself:
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net")]
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (log4net.Repository.Hierarchy.Logger curLog in
log4net.LogManager.GetRepository().GetCurrentLoggers())
{
Console.WriteLine("logger {0} - level {1} ",
curLog.Name,curLog.Level);
foreach (log4net.Appender.IAppender curAppender in
curLog.Appenders )
{
Console.WriteLine("{0} - {1}", curAppender.Name,
curAppender.GetType().FullName);
}
}
Console.ReadLine();
}
}
}
Hard to say why your FileAppender crashes. Are you using the target
file in other processes? Perhaps log4net is not able to open the
FileHandle and runs into the 'cannot write to closed appender'
exception?
Re: Error destroying my productivity Please Help!: log4net:ERROR [] Attempted to append to closed appender named []
Posted by Ron Grabowski <ro...@yahoo.com>.
Ross' writeup is correct.
This is not the correct way to define a logger:
<logger name="Invoicing">
<level value="DEBUG" />
<appender-ref ref="AdoNetAppender" />
</logger>
<!-- WRONG -->
<logger name="Invoicing">
<level value="FATAL" />
<appender-ref ref="FileAppender" />
</logger>
That's the not the documented way to define loggers so I'd say that behavior is undefined...in this case it throws an exception that can probably be guarded against fairly easily.
________________________________
From: Ross Hinkley <ro...@gmail.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Wednesday, April 8, 2009 12:07:37 PM
Subject: Re: Error destroying my productivity Please Help!: log4net:ERROR [] Attempted to append to closed appender named []
Omatase,
What you want would be something like the following (I'm guessing):
<log4net debug="false" threshold="ALL" >
<appender name="WarningAppender" type="log4net.Appender.ConsoleAppender">
<threshold value="WARN"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[WarningAppender] - %message%newline" />
</layout>
</appender>
<appender name="InfoAppender" type="log4net.Appender.ConsoleAppender">
<threshold value="INFO"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[InfoAppender] - %message%newline" />
</layout>
</appender>
<root>
<appender-ref ref="WarningAppender" />
<appender-ref ref="InfoAppender"/>
</root>
</log4net>
This way, if you log to the same logger, you'll get two separate messages in (potentially) two separate places.
It sounds like you want to tackle a fairly common scenario: When your application encounters a fatal error, you want to receive a notification about it. You could set up your SNMP appender to have a threshold of FATAL. You would also receive that error in the other appenders you have set up. Typically, I would think you wouldn't care if you get the fatal error logged multiple times, especially so you could figure out (from the DEBUG log, for example) what your application was trying to do when the error occurred.
Does that make sense?
-Ross
On Wed, Apr 8, 2009 at 10:33 AM, omatase <Om...@gmail.com> wrote:
Daniel Marohn wrote:
>
> Hi!
>
> ...
> Someone else might have an application that they would like to send
> DEBUG messages to the FileAppender
> even though my application may only send FATAL
> ...
>
> this is, why you have different logger.
> from your first post:
>
> <logger name="Invoicing">
> ...
> </logger>
>
> <logger name="Invoicing">
> ...
> </logger>
>
>
Yes, that *is* why I am doing that
Daniel Marohn wrote:
>
>
> this makes no sense. You configure the logger 'Invoicing' and later
> you configure the SAME logger with different properties. How do you
> want to access these 'two' loggers from your code?
> LogManger.GetLogger("Invoicing, but please first version") ? ;-)
>
log4net is intelligent enough to handle this.
When you call :
log4net.LogManager.GetLogger(loggerName).Debug(message, exception);
or
log4net.LogManager.GetLogger(loggerName).Error(message, exception);
It will use the logger defined with value="DEBUG"
But, when you call
log4net.LogManager.GetLogger(loggerName).Fatal(message, exception);
log4net will use the logger defined with value="FATAL"
This allows me to use the same loggerName throughout my application, and
have FATAL messages logged in a different manner. FATAL messages are more
urgent and require immediate attention for this I will be using an
SnmpAppender that will send the messages directly to our critical problem
monitoring system.
Daniel Marohn wrote:
>
> You can do this:
>
> <appender name="consoleTestAppender"
> type="log4net.Appender.ConsoleAppender" >
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date %-5level %logger - %message%newline"
> />
> </layout>
> </appender>
>
> <logger name="Invoicing.Application1">
> <level value="ERROR" />
> <appender-ref ref="consoleTestAppender" />
> </logger>
>
> <logger name="Invoicing.Application2">
> <level value="WARN" />
> <appender-ref ref="consoleTestAppender" />
> </logger>
>
> now you have two different loggers (one for each app), using the same
> appender. And you can set the Level per Logger.
>
>
The invoicing application is a single application. If I were to define
multiple loggers with different names I might do something like this
instead:
<logger name="Invoicing.Logger1">
<level value="FATAL" />
<appender-ref ref="consoleTestAppender" />
</logger>
<logger name="Invoicing.Logger2">
<level value="WARN" />
<appender-ref ref="consoleTestAppender" />
</logger>
The problem here is I am trying to send my critical errors to Snmp, so in my
code I would have to remember the logger name I am using for critical errors
(in this case Invoicing.Logger1). It is much simpler to just have to
remember to call ".Fatal" when I have a critical error and not have to
remember the loggername that was meant to handle fatal errors.
--
View this message in context: http://www.nabble.com/Error-destroying-my-productivity-Please-Help%21%3A-log4net%3AERROR----Attempted-to-append-to-closed-appender-named----tp22939427p22953058.html
Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by Ross Hinkley <ro...@gmail.com>.
Omatase,
What you want would be something like the following (I'm guessing):
<log4net debug="false" threshold="ALL" >
<appender name="WarningAppender"
type="log4net.Appender.ConsoleAppender">
<threshold value="WARN"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[WarningAppender] - %message%newline"
/>
</layout>
</appender>
<appender name="InfoAppender" type="log4net.Appender.ConsoleAppender">
<threshold value="INFO"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[InfoAppender] - %message%newline" />
</layout>
</appender>
<root>
<appender-ref ref="WarningAppender" />
<appender-ref ref="InfoAppender"/>
</root>
</log4net>
This way, if you log to the same logger, you'll get two separate messages in
(potentially) two separate places.
It sounds like you want to tackle a fairly common scenario: When your
application encounters a fatal error, you want to receive a notification
about it. You could set up your SNMP appender to have a threshold of
FATAL. You would also receive that error in the other appenders you have
set up. Typically, I would think you wouldn't care if you get the fatal
error logged multiple times, especially so you could figure out (from the
DEBUG log, for example) what your application was trying to do when the
error occurred.
Does that make sense?
-Ross
On Wed, Apr 8, 2009 at 10:33 AM, omatase <Om...@gmail.com> wrote:
>
>
>
> Daniel Marohn wrote:
> >
> > Hi!
> >
> > ...
> > Someone else might have an application that they would like to send
> > DEBUG messages to the FileAppender
> > even though my application may only send FATAL
> > ...
> >
> > this is, why you have different logger.
> > from your first post:
> >
> > <logger name="Invoicing">
> > ...
> > </logger>
> >
> > <logger name="Invoicing">
> > ...
> > </logger>
> >
> >
>
> Yes, that *is* why I am doing that
>
>
> Daniel Marohn wrote:
> >
> >
> > this makes no sense. You configure the logger 'Invoicing' and later
> > you configure the SAME logger with different properties. How do you
> > want to access these 'two' loggers from your code?
> > LogManger.GetLogger("Invoicing, but please first version") ? ;-)
> >
>
> log4net is intelligent enough to handle this.
>
> When you call :
>
> log4net.LogManager.GetLogger(loggerName).Debug(message, exception);
> or
> log4net.LogManager.GetLogger(loggerName).Error(message, exception);
>
> It will use the logger defined with value="DEBUG"
>
> But, when you call
>
> log4net.LogManager.GetLogger(loggerName).Fatal(message, exception);
>
> log4net will use the logger defined with value="FATAL"
>
> This allows me to use the same loggerName throughout my application, and
> have FATAL messages logged in a different manner. FATAL messages are more
> urgent and require immediate attention for this I will be using an
> SnmpAppender that will send the messages directly to our critical problem
> monitoring system.
>
>
> Daniel Marohn wrote:
> >
> > You can do this:
> >
> > <appender name="consoleTestAppender"
> > type="log4net.Appender.ConsoleAppender" >
> > <layout type="log4net.Layout.PatternLayout">
> > <conversionPattern value="%date %-5level %logger -
> %message%newline"
> > />
> > </layout>
> > </appender>
> >
> > <logger name="Invoicing.Application1">
> > <level value="ERROR" />
> > <appender-ref ref="consoleTestAppender" />
> > </logger>
> >
> > <logger name="Invoicing.Application2">
> > <level value="WARN" />
> > <appender-ref ref="consoleTestAppender" />
> > </logger>
> >
> > now you have two different loggers (one for each app), using the same
> > appender. And you can set the Level per Logger.
> >
> >
>
> The invoicing application is a single application. If I were to define
> multiple loggers with different names I might do something like this
> instead:
>
> <logger name="Invoicing.Logger1">
> <level value="FATAL" />
> <appender-ref ref="consoleTestAppender" />
> </logger>
>
> <logger name="Invoicing.Logger2">
> <level value="WARN" />
> <appender-ref ref="consoleTestAppender" />
> </logger>
>
> The problem here is I am trying to send my critical errors to Snmp, so in
> my
> code I would have to remember the logger name I am using for critical
> errors
> (in this case Invoicing.Logger1). It is much simpler to just have to
> remember to call ".Fatal" when I have a critical error and not have to
> remember the loggername that was meant to handle fatal errors.
>
> --
> View this message in context:
> http://www.nabble.com/Error-destroying-my-productivity-Please-Help%21%3A-log4net%3AERROR----Attempted-to-append-to-closed-appender-named----tp22939427p22953058.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>
>
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by Web Developer <sp...@googlemail.com>.
2009/4/8 omatase <Om...@gmail.com>
>
>
> Daniel Marohn wrote:
> >
> > I did some research about this
> >
> > I checked the log4net sources. The error is thrown in
> > AppenderSkelleton (the base class of all appenders).
> > public void DoAppend(LoggingEvent[] loggingEvents) {
> > ..
> > if (m_closed)
> > {
> > ErrorHandler.Error("Attempted to append to closed appender named
> > ["+m_name+"].");
> > return;
> > }
> > }
> >
> > m_closed in only set in
> > public void Close()
> >
> > it reads in code docu:
> > It is a programming error to append to a closed appender.
> >
> > Perhaps this is really a bug in one of the log4net appenders.
> >
> > Can you post a simple as possible config, that reproduces the error on
> > your system? I will try to reproduce this and debug into log4net to
> > see whats going wrong with the appender.
> >
> >
>
> Thanks for your help. Following is a minimalist example of one that fails.
> The error it causes is "log4net:ERROR [FileAppender] Attempted to append to
> closed appender named [FileAppender]." and can be seen in the Visual Studio
> "Output" window.
>
>
> <log4net>
> <root>
> <level value="DEBUG" />
> <appender-ref ref="FileAppender" />
> </root>
> <logger name="Invoicing">
> <level value="DEBUG" />
> <appender-ref ref="FileAppender" />
> </logger>
> <logger name="Invoicing">
> <level value="FATAL" />
> <appender-ref ref="FileAppenderFatal" />
> </logger>
> <!-- Setup the root category, add the appenders and set the default
> level -->
> <appender name="FileAppender" type="log4net.Appender.FileAppender">
> <file value="C:\Log.txt" />
> <appendToFile value="true" />
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date [%thread] %-5level %logger
> [%property{NDC}] - %message%newline" />
> </layout>
> </appender>
> <appender name="FileAppenderFatal" type="log4net.Appender.FileAppender">
> <file value="C:\LogFatal.txt" />
> <appendToFile value="true" />
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date [%thread] %-5level %logger
> [%property{NDC}] - %message%newline" />
> </layout>
> </appender>
> </log4net>
>
> You'll see that although the example *may* not be practical, it should be
> possible. It's not super realistic for someone to want a FileAppender only
> for FATAL messages although it *could* happen. I replaced the
> AdoNetAppender
> with the FileAppenderFatal in the interest of making the smallest possible
> reproducible configuration.
>
> Interestingly, this configuration does *not* reproduce the error:
>
> <log4net>
> <root>
> <level value="DEBUG" />
> <appender-ref ref="FileAppender" />
> </root>
> <logger name="Invoicing">
> <level value="FATAL" />
> <appender-ref ref="FileAppenderFatal" />
> </logger>
> <logger name="Invoicing">
> <level value="DEBUG" />
> <appender-ref ref="FileAppender" />
> </logger>
> <!-- Setup the root category, add the appenders and set the default
> level -->
> <appender name="FileAppender" type="log4net.Appender.FileAppender">
> <file value="C:\Log.txt" />
> <appendToFile value="true" />
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date [%thread] %-5level %logger
> [%property{NDC}] - %message%newline" />
> </layout>
> </appender>
> <appender name="FileAppenderFatal" type="log4net.Appender.FileAppender">
> <file value="C:\LogFatal.txt" />
> <appendToFile value="true" />
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date [%thread] %-5level %logger
> [%property{NDC}] - %message%newline" />
> </layout>
> </appender>
> </log4net>
>
> The only difference between the two was I swapped the positioning of the
> two
> loggers.
> --
> View this message in context:
> http://www.nabble.com/Error-destroying-my-productivity-Please-Help%21%3A-log4net%3AERROR----Attempted-to-append-to-closed-appender-named----tp22939427p22960695.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>
>
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by omatase <Om...@gmail.com>.
Daniel Marohn wrote:
>
> I did some research about this
>
> I checked the log4net sources. The error is thrown in
> AppenderSkelleton (the base class of all appenders).
> public void DoAppend(LoggingEvent[] loggingEvents) {
> ..
> if (m_closed)
> {
> ErrorHandler.Error("Attempted to append to closed appender named
> ["+m_name+"].");
> return;
> }
> }
>
> m_closed in only set in
> public void Close()
>
> it reads in code docu:
> It is a programming error to append to a closed appender.
>
> Perhaps this is really a bug in one of the log4net appenders.
>
> Can you post a simple as possible config, that reproduces the error on
> your system? I will try to reproduce this and debug into log4net to
> see whats going wrong with the appender.
>
>
Thanks for your help. Following is a minimalist example of one that fails.
The error it causes is "log4net:ERROR [FileAppender] Attempted to append to
closed appender named [FileAppender]." and can be seen in the Visual Studio
"Output" window.
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
</root>
<logger name="Invoicing">
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
</logger>
<logger name="Invoicing">
<level value="FATAL" />
<appender-ref ref="FileAppenderFatal" />
</logger>
<!-- Setup the root category, add the appenders and set the default
level -->
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="C:\Log.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="FileAppenderFatal" type="log4net.Appender.FileAppender">
<file value="C:\LogFatal.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
You'll see that although the example *may* not be practical, it should be
possible. It's not super realistic for someone to want a FileAppender only
for FATAL messages although it *could* happen. I replaced the AdoNetAppender
with the FileAppenderFatal in the interest of making the smallest possible
reproducible configuration.
Interestingly, this configuration does *not* reproduce the error:
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
</root>
<logger name="Invoicing">
<level value="FATAL" />
<appender-ref ref="FileAppenderFatal" />
</logger>
<logger name="Invoicing">
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
</logger>
<!-- Setup the root category, add the appenders and set the default
level -->
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="C:\Log.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="FileAppenderFatal" type="log4net.Appender.FileAppender">
<file value="C:\LogFatal.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
The only difference between the two was I swapped the positioning of the two
loggers.
--
View this message in context: http://www.nabble.com/Error-destroying-my-productivity-Please-Help%21%3A-log4net%3AERROR----Attempted-to-append-to-closed-appender-named----tp22939427p22960695.html
Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by Daniel Marohn <ma...@sipgate.de>.
I did some research about this
I checked the log4net sources. The error is thrown in
AppenderSkelleton (the base class of all appenders).
public void DoAppend(LoggingEvent[] loggingEvents) {
..
if (m_closed)
{
ErrorHandler.Error("Attempted to append to closed appender named
["+m_name+"].");
return;
}
}
m_closed in only set in
public void Close()
it reads in code docu:
It is a programming error to append to a closed appender.
Perhaps this is really a bug in one of the log4net appenders.
Can you post a simple as possible config, that reproduces the error on
your system? I will try to reproduce this and debug into log4net to
see whats going wrong with the appender.
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by Daniel Marohn <ma...@sipgate.de>.
>
> log4net is intelligent enough to handle this.
>
thx for pointing this out.
what about this:
<appender name="FatalSmtAppender" type= ...>
<threshold value="WARN"/>
</appender>
<root>
<appender-ref ref="FatalSmtAppender" />
</root>
this will deliver all Messages to the appender, but only fatals are delivered...
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by omatase <Om...@gmail.com>.
Daniel Marohn wrote:
>
> Hi!
>
> ...
> Someone else might have an application that they would like to send
> DEBUG messages to the FileAppender
> even though my application may only send FATAL
> ...
>
> this is, why you have different logger.
> from your first post:
>
> <logger name="Invoicing">
> ...
> </logger>
>
> <logger name="Invoicing">
> ...
> </logger>
>
>
Yes, that *is* why I am doing that
Daniel Marohn wrote:
>
>
> this makes no sense. You configure the logger 'Invoicing' and later
> you configure the SAME logger with different properties. How do you
> want to access these 'two' loggers from your code?
> LogManger.GetLogger("Invoicing, but please first version") ? ;-)
>
log4net is intelligent enough to handle this.
When you call :
log4net.LogManager.GetLogger(loggerName).Debug(message, exception);
or
log4net.LogManager.GetLogger(loggerName).Error(message, exception);
It will use the logger defined with value="DEBUG"
But, when you call
log4net.LogManager.GetLogger(loggerName).Fatal(message, exception);
log4net will use the logger defined with value="FATAL"
This allows me to use the same loggerName throughout my application, and
have FATAL messages logged in a different manner. FATAL messages are more
urgent and require immediate attention for this I will be using an
SnmpAppender that will send the messages directly to our critical problem
monitoring system.
Daniel Marohn wrote:
>
> You can do this:
>
> <appender name="consoleTestAppender"
> type="log4net.Appender.ConsoleAppender" >
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date %-5level %logger - %message%newline"
> />
> </layout>
> </appender>
>
> <logger name="Invoicing.Application1">
> <level value="ERROR" />
> <appender-ref ref="consoleTestAppender" />
> </logger>
>
> <logger name="Invoicing.Application2">
> <level value="WARN" />
> <appender-ref ref="consoleTestAppender" />
> </logger>
>
> now you have two different loggers (one for each app), using the same
> appender. And you can set the Level per Logger.
>
>
The invoicing application is a single application. If I were to define
multiple loggers with different names I might do something like this
instead:
<logger name="Invoicing.Logger1">
<level value="FATAL" />
<appender-ref ref="consoleTestAppender" />
</logger>
<logger name="Invoicing.Logger2">
<level value="WARN" />
<appender-ref ref="consoleTestAppender" />
</logger>
The problem here is I am trying to send my critical errors to Snmp, so in my
code I would have to remember the logger name I am using for critical errors
(in this case Invoicing.Logger1). It is much simpler to just have to
remember to call ".Fatal" when I have a critical error and not have to
remember the loggername that was meant to handle fatal errors.
--
View this message in context: http://www.nabble.com/Error-destroying-my-productivity-Please-Help%21%3A-log4net%3AERROR----Attempted-to-append-to-closed-appender-named----tp22939427p22953058.html
Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by Daniel Marohn <ma...@sipgate.de>.
Hi!
...
Someone else might have an application that they would like to send
DEBUG messages to the FileAppender
even though my application may only send FATAL
...
this is, why you have different logger.
from your first post:
<logger name="Invoicing">
...
</logger>
<logger name="Invoicing">
...
</logger>
this makes no sense. You configure the logger 'Invoicing' and later
you configure the SAME logger with different properties. How do you
want to access these 'two' loggers from your code?
LogManger.GetLogger("Invoicing, but please first version") ? ;-)
You can do this:
<appender name="consoleTestAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger - %message%newline" />
</layout>
</appender>
<logger name="Invoicing.Application1">
<level value="ERROR" />
<appender-ref ref="consoleTestAppender" />
</logger>
<logger name="Invoicing.Application2">
<level value="WARN" />
<appender-ref ref="consoleTestAppender" />
</logger>
now you have two different loggers (one for each app), using the same
appender. And you can set the Level per Logger.
Perhaps you want to define another one:
<logger name="Invoicing">
<level value="ALL" />
<appender-ref ref="consoleTestAppender" />
</logger>
now you have also the root logger (Invoicing). So you can configure
global settings for all Invoicing loggers or for every single one ...
have fun!
Daniel
Re: Error destroying my productivity Please Help!: log4net:ERROR []
Attempted to append to closed appender named []
Posted by omatase <Om...@gmail.com>.
Ross Hinkley wrote:
>
> You can specify a threshold value in the appender. That would allow you
> to
> log messages from a given level and higher. For example, as a child to
> the
> appender node:
>
> <threshold value="INFO">
>
> would log Info messages, Warning messages, and so on. From there, you can
> use Ron's suggestion for controlling what you want to see overall and to
> manage multiple appenders.
>
> Omatase, if you need a more complete example, let me know.
>
> -Ross
>
>
I would love an example if you wouldn't mind. It sounds like what you are
suggesting might not work in my situation though. I want to make these
appenders available for any logging level. Someone else might have an
application that they would like to send DEBUG messages to the FileAppender
even though my application may only send FATAL messages to the same
appender.
Ross Hinkley wrote:
>
> If I understand your question, Omatase, it sounds like you want to log one
> log level per file, maybe? I'm not certain you can specify an upper
> threshold to an appender. I've never used log4net in such a fashion.
> Does
> anyone know if you can set an upper limit on an appender?
>
Since this is a service to be used by all applications developed at our
company it could potentially be used differently by each application. For my
application (The Invoicing example) I want to be able to send FATAL messages
to the FileAppender and DEBUG messages to the AdoNetAppender not separated
by file.
--
View this message in context: http://www.nabble.com/Error-destroying-my-productivity-Please-Help%21%3A-log4net%3AERROR----Attempted-to-append-to-closed-appender-named----tp22939427p22951693.html
Sent from the Log4net - Users mailing list archive at Nabble.com.