RE: Log an Exception

"Collier, Mike" <[email protected]> Wed, 15 Dec 2004 10:41:56 -0500
Newsgroups gmane.comp.windows.dotnet.log4net.devel
Message-ID <[email protected]>
First, thanks for the response and explanation.

I am using the second method - Debug(object,Exception).  Using
PatternLayout's %m conversion character, the Exception does appear to be
appended to the output of the pattern.  But, it doesn't appear to be
using the Exception's ToString() method.  For example, with Log4NET, the
Exception appears like this:
	Exception: System.ApplicationException
	Message: go bucks
	Source: Log4NETTest
	   at Log4NETTest.Class1.Test() in
d:\development\projects\testprojects\log4nettest\class1.cs:line 24
	   at Log4NETTest.Class1.Main(String[] args) in
d:\development\projects\testprojects\log4nettest\class1.cs:line 52
But if I just call the ToString() method, I see something like this:
	System.ApplicationException: go bucks
   		at Log4NETTest.Class1.Test() in
d:\development\projects\testprojects\log4nettest\class1.cs:line 24
		at Log4NETTest.Class1.Main(String[] args) in
d:\development\projects\testprojects\log4nettest\class1.cs:line 52

Is Log4NET rendering the Exception differently, or am I totally off base
here?

If I wanted to log the Exception message apart from the message, I would
need to create my own layout and parser, correct?  For example, derive
my custom layout and parser from PatternLayout and PatternParser?


On a side note, should I post any future response to this thread on the
new [email protected] list?  I noticed that the
Sourceforge.net lists are closed.


Thanks,
Mike

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nicko
Cadell
Sent: Wednesday, December 15, 2004 8:21 AM
To: [email protected]
Subject: RE: [Log4net-devel] Log an Exception

Mike,

Are you only logging an exception object or are you logging some message
in addition to the exception?

The log4net ILog interface supports methods like:

Debug(object)
Debug(object,Exception)

Are you using the first or second method?
log4net makes a distinction between the message (which is an object) and
the additional exception. Typically a message is logged and may have an
optional exception attached. log4net stores and processes the exception
separately to the message. Note that as the message is an object it may
be an Exception instance, but log4net still treats this as the message
object, not the additional exception data.

The message is rendered using the PatternLayout, the exception is added
to the output if the layout does not render it.
The ExceptionLayout takes the optional exception, not the message, and
rendered that. It is only really used by the AdoNetAppender which uses
multiple layouts.

The PatternLayout's %m pattern renders the message object to a string.
The PatternLayout does not process any additional exception that may
have been specified. If there is an additional exception its ToString
method is called an that is appended to the output of the pattern.

Whether the exception is passed as the message or additional exception
the object is not broken up into component parts - type, message, stack
trace, inner exception. These parts cannot be logged separately using
the built-in Layouts.

Nicko

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of=20
> Collier, Mike
> Sent: 13 December 2004 23:42
> To: [email protected];
> [email protected]
> Subject: [Log4net-devel] Log an Exception
>=20
> How would I log an exception (type, message, and stack trace) using,=20
> for example, the ConsoleAppender or FileAppender?  It seems that the=20
> "%m"
> conversion character in PatternLayout prints my log message, and the=20
> exception type and message, but not the stack trace.
> I see that the ExceptionLayout prints out the exception information. =20
> I don't see a way to use the ExceptionLayout with appenders like the=20
> ConsoleAppender.  I could use the ExceptionLayout with the=20
> ADONetAppender though.
>=20
> Do I need to implement my own conversion character?
>=20
> I'm using Log4NET 1.2.0 beta 8.
>=20
>=20
> Thanks!
>=20
>=20
>=20
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide Read honest & candid=20
> reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.=20
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Log4net-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/log4net-devel
>=20


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide Read honest & candid
reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.=20
http://productguide.itmanagersjournal.com/
_______________________________________________
Log4net-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/log4net-devel


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/