aus1977 | 3 Feb 2008 14:05
Picon

Error handling inside log4net


How does log4net handling exception of itself
--

-- 
View this message in context: http://www.nabble.com/Error-handling-inside-log4net-tp15253276p15253276.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Ron Grabowski | 4 Feb 2008 01:09
Picon
Favicon

Re: Error handling inside log4net

The process is explained near the bottom of this page:

 http://logging.apache.org/log4net/release/faq.html

Internal messages/errors are written to Console.Out and System.Diagnostics.Trace. If you want to
capture those message you'll need to write a TraceListener or redirect Console.Out. 

The latest code in Subversion also exposes a LogReceived event on the internal LogLog class (there's
probably a better name for the event). The Configure methods on BasicConfigurator and XmlConfigurator
will return a list of internal messages/errors. Its also possible to disable output to Console.Out and
System.Diagnostics.Trace and only subscribe to the event.

----- Original Message ----
From: aus1977 <aus1977 <at> gmail.com>
To: log4net-user <at> logging.apache.org
Sent: Sunday, February 3, 2008 8:05:22 AM
Subject: Error handling inside log4net

How 
does 
log4net 
handling 
exception 
of 
itself
--

-- 
View 
this 
message 
in 
(Continue reading)

Parrish, Ken | 4 Feb 2008 15:50

Remote listening of server log stream ...

I have a scenario where I have a server with several ADO.NET and Windows services running.  Under normal operation, the applications write log messages of various severities to a rolling file(s), Windows event viewer, and e-mail via the SmtpAppender.

 

I would like to set up a logger/appender that would allow remote listening in on the stream of logging messages.  In this case, the server runs continuously and is constantly generating a stream of logging events to a RollingFileAppender.  From time to time, I’d like to ‘attach’ to the logging output, remotely from a separate host and ‘listen in’ on the steam of messages being generated.

 

I looked into the UdpAppender in combination with log4netview or logview4net.  But it seems that the UdpAppender requires specification of a specific Host and TCP port.  I didn’t see a way that I could connect in to listen to the UDP stream remotely.

 

I also considered writing a separate Windows Service that supported .NET remoting to which log messages were routed.  I could then ‘subscribe’ via .NET remoting and remote message sinks listen in on the log stream.  Seems like a lot of work for a simple task.

 

I noticed the .NET RemotingAppender in the example appender source code, but am not sure if that will work.

 

Has anyone needed this type of remote ‘log listening’ capability and have a suggestion for a solution or approach?

 

Thanks,

 

Ken Parrish

Gomez, Inc.

Parrish, Ken | 4 Feb 2008 17:09

A caching / metering SMTP appender ...

Several weeks ago, I posted a  couple of notes on this list on the subject of metering of SMTP log events and an elapsed time evaluator.  The objective was to design a log4net extension that would accommodate the caching and metering of log events sent via SMTP.  In a situation where a server is failing and generating large quantities of severe log events that need to be sent via SMTP to notify operational personnel, the problem was to find a way to collect blocks of messages and send them in a single e-mail message.  Since then, I’ve notice several other posting referring to similar problems.

 

 

Ron Grabowski sent me some snippets of code suggesting possible approaches to the elapsed timer portion of the problem which got me started on creating a more comprehensive solution to this problem.

 

Below / attached is the source code and sample configuration for a caching SMTP appender.  There are two configurable criteria for this appender:

 

FlushInterval     TimeSpan indicating maximum elapsed time between generation of e-mail messages.  Needed in cases where there is a quiescent period of time after the caching of critical errors.

 

MaxCachedMessages Integer indicate the maximum number of log messages to cache before flushing to e-mail.  This total does not include ‘context’ log events that are normally and optionally included in SMTP log event postings.

 

I wanted to share this with other log4net users, but also ask for feedback regarding it’s design.  Have I overlooked any operational issues, resource management, etc.  Is there a way to gracefully shutdown the time when log4net is shutdown?  Any other comments or feedback would be appreciated.

 

Thanks,

 

Ken Parrish

 

 

 

            <appender name="SmtpCachingAppender" type="Log4NetExtensions.SmtpCachingAppender, Log4NetExtensions">

                  <to value="name <at> domain.com" />

                  <from value="name <at> domain.com" />

                  <subject value="Log4net test message" />

                  <smtpHost value="smtphost.com" />

                  <bufferSize value="512" />

                  <lossy value="true" />

                  <evaluator type="log4net.Core.LevelEvaluator">

                        <threshold value="ERROR"/>

                  </evaluator>

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

                        <param name="ConversionPattern" value="%date{yyyy-MM-dd HH:mm:ss.fff} [%t] %-5level %logger - %message%newline%exception" />

                  </layout>

                  <FlushInterval value="00:05:00" />

                  <MaxCachedMessages value="20" />

            </appender>

 

 

 

 

using System;

using System.Collections.Generic;

 

using log4net.Appender;

using log4net.Core;

 

namespace Log4NetExtensions

{

      public class SmtpCachingAppender : SmtpAppender

      {

            int _maxCachedMessages = 20; // Config option

            TimeSpan _flushInterval = new TimeSpan(0, 5, 00); // Config option

            System.Threading.Timer _timer;

            bool _timedFlush = false;

            int _numCachedMessages = 0;

            List<LoggingEvent> _loggingEvents = new List<LoggingEvent>();

 

            /// <summary>

            ///         TimeSpan indicating the maximum period of time elapsed before sending

            ///         any cached SMTP log events.

            /// </summary>

            public TimeSpan FlushInterval

            {

                  get { return this._flushInterval; }

                  set { this._flushInterval = value; }

            }

 

            /// <summary>

            ///         Maximium number of SMTP events to cache before sending via SMTP.

            /// </summary>

            public int MaxCachedMessages

            {

                  get { return this._maxCachedMessages; }

                  set { this._maxCachedMessages = value; }

            }

 

            /// <summary>

            ///         Create a timer that fires to force flushing cached log events

            ///         via SMTP at a specified interval.

            /// </summary>

            public override void ActivateOptions()

            {

                  this._timer = new System.Threading.Timer(

                        new System.Threading.TimerCallback(OnTimer),

                        null,

                        TimeSpan.Zero,

                        this._flushInterval);

 

                  base.ActivateOptions();

            }

 

            void OnTimer(Object stateInfo)

            {

                  this._timedFlush = true;

                  Flush(true);

            }

 

            protected override void SendBuffer(LoggingEvent[] events)

            {

                  foreach (LoggingEvent loggingEvent in events)

                  {

                        this._loggingEvents.Add(loggingEvent);

                  }

 

                  this._numCachedMessages++;

                  if ((this._numCachedMessages >= this._maxCachedMessages) || this._timedFlush)

                  {

                        if (this._loggingEvents.Count > 0)

                        {

                              LoggingEvent[] bufferedEvents = this._loggingEvents.ToArray();

 

                              base.SendBuffer(bufferedEvents);

 

                              this._loggingEvents.Clear();

                        }

                        // Reset cache buffer conditions.

                        this._numCachedMessages = 0;

                        this._timedFlush = false;

                  }

            }

      }

}

 

Attachment (SmtpCachingAppender.cs): application/octet-stream, 2113 bytes
Srinivas Sayana | 4 Feb 2008 17:11

need working sorce code for Log4Net

Hi,

 

I was trying to download the log4net zip file and trying to extract it is giving me error, can anyone help me in finding the working code.

 

Thanks

Srini

 

From: Parrish, Ken [mailto:KParrish <at> gomez.com]
Sent: Monday, February 04, 2008 11:10 AM
To: log4net-user <at> logging.apache.org
Subject: A caching / metering SMTP appender ...

 

Several weeks ago, I posted a  couple of notes on this list on the subject of metering of SMTP log events and an elapsed time evaluator.  The objective was to design a log4net extension that would accommodate the caching and metering of log events sent via SMTP.  In a situation where a server is failing and generating large quantities of severe log events that need to be sent via SMTP to notify operational personnel, the problem was to find a way to collect blocks of messages and send them in a single e-mail message.  Since then, I’ve notice several other posting referring to similar problems.

 

 

Ron Grabowski sent me some snippets of code suggesting possible approaches to the elapsed timer portion of the problem which got me started on creating a more comprehensive solution to this problem.

 

Below / attached is the source code and sample configuration for a caching SMTP appender.  There are two configurable criteria for this appender:

 

FlushInterval     TimeSpan indicating maximum elapsed time between generation of e-mail messages.  Needed in cases where there is a quiescent period of time after the caching of critical errors.

 

MaxCachedMessages Integer indicate the maximum number of log messages to cache before flushing to e-mail.  This total does not include ‘context’ log events that are normally and optionally included in SMTP log event postings.

 

I wanted to share this with other log4net users, but also ask for feedback regarding it’s design.  Have I overlooked any operational issues, resource management, etc.  Is there a way to gracefully shutdown the time when log4net is shutdown?  Any other comments or feedback would be appreciated.

 

Thanks,

 

Ken Parrish

 

 

 

            <appender name="SmtpCachingAppender" type="Log4NetExtensions.SmtpCachingAppender, Log4NetExtensions">

                  <to value="name <at> domain.com" />

                  <from value="name <at> domain.com" />

                  <subject value="Log4net test message" />

                  <smtpHost value="smtphost.com" />

                  <bufferSize value="512" />

                  <lossy value="true" />

                  <evaluator type="log4net.Core.LevelEvaluator">

                        <threshold value="ERROR"/>

                  </evaluator>

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

                        <param name="ConversionPattern" value="%date{yyyy-MM-dd HH:mm:ss.fff} [%t] %-5level %logger - %message%newline%exception" />

                  </layout>

                  <FlushInterval value="00:05:00" />

                  <MaxCachedMessages value="20" />

            </appender>

 

 

 

 

using System;

using System.Collections.Generic;

 

using log4net.Appender;

using log4net.Core;

 

namespace Log4NetExtensions

{

      public class SmtpCachingAppender : SmtpAppender

      {

            int _maxCachedMessages = 20; // Config option

            TimeSpan _flushInterval = new TimeSpan(0, 5, 00); // Config option

            System.Threading.Timer _timer;

            bool _timedFlush = false;

            int _numCachedMessages = 0;

            List<LoggingEvent> _loggingEvents = new List<LoggingEvent>();

 

            /// <summary>

            ///         TimeSpan indicating the maximum period of time elapsed before sending

            ///         any cached SMTP log events.

            /// </summary>

            public TimeSpan FlushInterval

            {

                  get { return this._flushInterval; }

                  set { this._flushInterval = value; }

            }

 

            /// <summary>

            ///         Maximium number of SMTP events to cache before sending via SMTP.

            /// </summary>

            public int MaxCachedMessages

            {

                  get { return this._maxCachedMessages; }

                  set { this._maxCachedMessages = value; }

            }

 

            /// <summary>

            ///         Create a timer that fires to force flushing cached log events

            ///         via SMTP at a specified interval.

            /// </summary>

            public override void ActivateOptions()

            {

                  this._timer = new System.Threading.Timer(

                        new System.Threading.TimerCallback(OnTimer),

                        null,

                        TimeSpan.Zero,

                        this._flushInterval);

 

                  base.ActivateOptions();

            }

 

            void OnTimer(Object stateInfo)

            {

                  this._timedFlush = true;

                  Flush(true);

            }

 

            protected override void SendBuffer(LoggingEvent[] events)

            {

                  foreach (LoggingEvent loggingEvent in events)

                  {

                        this._loggingEvents.Add(loggingEvent);

                  }

 

                  this._numCachedMessages++;

                  if ((this._numCachedMessages >= this._maxCachedMessages) || this._timedFlush)

                  {

                        if (this._loggingEvents.Count > 0)

                        {

                              LoggingEvent[] bufferedEvents = this._loggingEvents.ToArray();

 

                              base.SendBuffer(bufferedEvents);

 

                              this._loggingEvents.Clear();

                        }

                        // Reset cache buffer conditions.

                        this._numCachedMessages = 0;

                        this._timedFlush = false;

                  }

            }

      }

}

 

Srinivas Sayana | 4 Feb 2008 17:30

need working Log4Net source

I have downloaded the source from incubating-log4net-1.2.10.zip,but I was not able to extract it. It throws an error. Can any one help me giving the working source.

 

From: Parrish, Ken [mailto:KParrish <at> gomez.com]
Sent: Monday, February 04, 2008 11:10 AM
To: log4net-user <at> logging.apache.org
Subject: A caching / metering SMTP appender ...

 

Several weeks ago, I posted a  couple of notes on this list on the subject of metering of SMTP log events and an elapsed time evaluator.  The objective was to design a log4net extension that would accommodate the caching and metering of log events sent via SMTP.  In a situation where a server is failing and generating large quantities of severe log events that need to be sent via SMTP to notify operational personnel, the problem was to find a way to collect blocks of messages and send them in a single e-mail message.  Since then, I’ve notice several other posting referring to similar problems.

 

 

Ron Grabowski sent me some snippets of code suggesting possible approaches to the elapsed timer portion of the problem which got me started on creating a more comprehensive solution to this problem.

 

Below / attached is the source code and sample configuration for a caching SMTP appender.  There are two configurable criteria for this appender:

 

FlushInterval     TimeSpan indicating maximum elapsed time between generation of e-mail messages.  Needed in cases where there is a quiescent period of time after the caching of critical errors.

 

MaxCachedMessages Integer indicate the maximum number of log messages to cache before flushing to e-mail.  This total does not include ‘context’ log events that are normally and optionally included in SMTP log event postings.

 

I wanted to share this with other log4net users, but also ask for feedback regarding it’s design.  Have I overlooked any operational issues, resource management, etc.  Is there a way to gracefully shutdown the time when log4net is shutdown?  Any other comments or feedback would be appreciated.

 

Thanks,

 

Ken Parrish

 

 

 

            <appender name="SmtpCachingAppender" type="Log4NetExtensions.SmtpCachingAppender, Log4NetExtensions">

                  <to value="name <at> domain.com" />

                  <from value="name <at> domain.com" />

                  <subject value="Log4net test message" />

                  <smtpHost value="smtphost.com" />

                  <bufferSize value="512" />

                  <lossy value="true" />

                  <evaluator type="log4net.Core.LevelEvaluator">

                        <threshold value="ERROR"/>

                  </evaluator>

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

                        <param name="ConversionPattern" value="%date{yyyy-MM-dd HH:mm:ss.fff} [%t] %-5level %logger - %message%newline%exception" />

                  </layout>

                  <FlushInterval value="00:05:00" />

                  <MaxCachedMessages value="20" />

            </appender>

 

 

 

 

using System;

using System.Collections.Generic;

 

using log4net.Appender;

using log4net.Core;

 

namespace Log4NetExtensions

{

      public class SmtpCachingAppender : SmtpAppender

      {

            int _maxCachedMessages = 20; // Config option

            TimeSpan _flushInterval = new TimeSpan(0, 5, 00); // Config option

            System.Threading.Timer _timer;

            bool _timedFlush = false;

            int _numCachedMessages = 0;

            List<LoggingEvent> _loggingEvents = new List<LoggingEvent>();

 

            /// <summary>

            ///         TimeSpan indicating the maximum period of time elapsed before sending

            ///         any cached SMTP log events.

            /// </summary>

            public TimeSpan FlushInterval

            {

                  get { return this._flushInterval; }

                  set { this._flushInterval = value; }

            }

 

            /// <summary>

            ///         Maximium number of SMTP events to cache before sending via SMTP.

            /// </summary>

            public int MaxCachedMessages

            {

                  get { return this._maxCachedMessages; }

                  set { this._maxCachedMessages = value; }

            }

 

            /// <summary>

            ///         Create a timer that fires to force flushing cached log events

            ///         via SMTP at a specified interval.

            /// </summary>

            public override void ActivateOptions()

            {

                  this._timer = new System.Threading.Timer(

                        new System.Threading.TimerCallback(OnTimer),

                        null,

                        TimeSpan.Zero,

                        this._flushInterval);

 

                  base.ActivateOptions();

            }

 

            void OnTimer(Object stateInfo)

            {

                  this._timedFlush = true;

                  Flush(true);

            }

 

            protected override void SendBuffer(LoggingEvent[] events)

            {

                  foreach (LoggingEvent loggingEvent in events)

                  {

                        this._loggingEvents.Add(loggingEvent);

                  }

 

                  this._numCachedMessages++;

                  if ((this._numCachedMessages >= this._maxCachedMessages) || this._timedFlush)

                  {

                        if (this._loggingEvents.Count > 0)

                        {

                              LoggingEvent[] bufferedEvents = this._loggingEvents.ToArray();

 

                              base.SendBuffer(bufferedEvents);

 

                              this._loggingEvents.Clear();

                        }

                        // Reset cache buffer conditions.

                        this._numCachedMessages = 0;

                        this._timedFlush = false;

                  }

            }

      }

}

 

Scott Deboy | 4 Feb 2008 19:02

RE: Remote listening of server log stream ...

Chainsaw provides a LogFilePatternReceiver that can tail log files on a local file system or available via HTTP.

 

Chainsaw also includes VFSLogFilePatternReceiver, which will let you tail log files remotely when if the files are accessible via ssh or any of the file systems supported by Jakarta commons-vfs (http://commons.apache.org/vfs/filesystems.html)

 

Scott Deboy
Principal Engineer
CO
MOTIV SYSTEMS
111 SW Columbia Street Ste. 950
Portland, OR  97201
Office: 503.224.7496
Direct Line: 503.821.6482
Cell: 503.997.1367
Fax: 503.222.0185
sdeboy <at> comotivsystems.com
www.comotivsystems.com

From: Parrish, Ken [mailto:KParrish <at> gomez.com]
Sent: Monday, February 04, 2008 6:50 AM
To: log4net-user <at> logging.apache.org
Subject: Remote listening of server log stream ...

 

I have a scenario where I have a server with several ADO.NET and Windows services running.  Under normal operation, the applications write log messages of various severities to a rolling file(s), Windows event viewer, and e-mail via the SmtpAppender.

 

I would like to set up a logger/appender that would allow remote listening in on the stream of logging messages.  In this case, the server runs continuously and is constantly generating a stream of logging events to a RollingFileAppender.  From time to time, I’d like to ‘attach’ to the logging output, remotely from a separate host and ‘listen in’ on the steam of messages being generated.

 

I looked into the UdpAppender in combination with log4netview or logview4net.  But it seems that the UdpAppender requires specification of a specific Host and TCP port.  I didn’t see a way that I could connect in to listen to the UDP stream remotely.

 

I also considered writing a separate Windows Service that supported .NET remoting to which log messages were routed.  I could then ‘subscribe’ via .NET remoting and remote message sinks listen in on the log stream.  Seems like a lot of work for a simple task.

 

I noticed the .NET RemotingAppender in the example appender source code, but am not sure if that will work.

 

Has anyone needed this type of remote ‘log listening’ capability and have a suggestion for a solution or approach?

 

Thanks,

 

Ken Parrish

Gomez, Inc.

Ron Grabowski | 5 Feb 2008 01:24
Picon
Favicon

Re: need working Log4Net source

I was able to open the file fine using WinRAR.

----- Original Message ----
From: Srinivas Sayana <srinivas.sayana <at> datumsoftware.com>
To: Log4NET User <log4net-user <at> logging.apache.org>
Sent: Monday, February 4, 2008 11:30:57 AM
Subject: need working Log4Net source

I have downloaded the source from incubating-log4net-1.2.10.zip,but I was not able to extract it. It throws an error. Can any one help me giving the working source.


jeusdi | 5 Feb 2008 13:20
Picon
Favicon

Log4Net used into Class library


I'm develping a little library, and I'm adding log features to it, now. The
problem is that I don't know How I Can configure Log4Net. In my code I
obtain a logger as:

private log4net.ILog logger =
log4net.LogManager.GetLogger(typeof(OnCloseSessionManager))

but, when I need to use it (the logger), it is null.

I also have this line in my code:
[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.xml",
Watch=true)]
but, the logger is null, yet. The beliee that this line find around the
application directory files as log4net.xml and configure the logs using this
xml file...

The log4net.xml file of my application (application that uses my class
library) is:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
     <appender name="exceptions" type="log4net.Appender.FileAppender">
         <file value="./exceptions.log" />
         <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
         <appendToFile value="true" />
         <layout type="log4net.Layout.PatternLayout">
             <conversionPattern value="%date %level %thread %logger -
%message%newline" />
         </layout>
     </appender>
     <root>
         <level value="ALL" />
         <appender-ref ref="exceptions" />
     </root>
</log4net>

Can you help me please?
I will appreciate a lot your help.
Thanks for all.
--

-- 
View this message in context: http://www.nabble.com/Log4Net-used-into-Class-library-tp15289024p15289024.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Radovan Raszka | 5 Feb 2008 14:09
Picon
Favicon

RE: Log4Net used into Class library

You must configure logging system first:

log4net.Config.XmlConfigurator.Configure(new
System.IO.FileInfo("mypath/to/log4net.xml"));
// after configuring you can get logger instance
logger = log4net.LogManager.GetLogger(typeof(OnCloseSessionManager))

If you can not configure log4net using XmlConfiguratorAtttribute, check
if config file is on the expected path (in the same directory as your
assembly)
R

-----Original Message-----
From: jeusdi [mailto:cabrejcr <at> terra.es] 
Sent: Tuesday, February 05, 2008 1:21 PM
To: log4net-user <at> logging.apache.org
Subject: Log4Net used into Class library

I'm develping a little library, and I'm adding log features to it, now.
The problem is that I don't know How I Can configure Log4Net. In my code
I obtain a logger as:

private log4net.ILog logger =
log4net.LogManager.GetLogger(typeof(OnCloseSessionManager))

but, when I need to use it (the logger), it is null.

I also have this line in my code:
[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.xml",
Watch=true)]
but, the logger is null, yet. The beliee that this line find around the
application directory files as log4net.xml and configure the logs using
this xml file...

The log4net.xml file of my application (application that uses my class
library) is:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
     <appender name="exceptions" type="log4net.Appender.FileAppender">
         <file value="./exceptions.log" />
         <lockingModel type="log4net.Appender.FileAppender+MinimalLock"
/>
         <appendToFile value="true" />
         <layout type="log4net.Layout.PatternLayout">
             <conversionPattern value="%date %level %thread %logger -
%message%newline" />
         </layout>
     </appender>
     <root>
         <level value="ALL" />
         <appender-ref ref="exceptions" />
     </root>
</log4net>

Can you help me please?
I will appreciate a lot your help.
Thanks for all.
--
View this message in context:
http://www.nabble.com/Log4Net-used-into-Class-library-tp15289024p1528902
4.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Gmane