logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Collier, Mike" <Mike_Coll...@stercomm.com>
Subject RE: [Log4net-devel] Log an Exception
Date Sat, 18 Dec 2004 01:24:51 GMT
What files do I need (from Log4NET's CVS repository) in order to get
Log4NET to use the Exceptions ToString() method when rendering an
exception?

If I should use the latest version from CVS, would I just need to derive
from the PatternLayout class and override the CreatePatternParser()
method to add my custom converter to the PatternParser.ConverterRegistry
hashtable?  Then, for the custom converter, just derive from
PatternLayoutConverter and override the Convert() method?

It seems like the namespace structure has changed since 1.2 beta 8.
Would I be better off just upgrading to the latest CVS version, or
upgrading these selected pieces?

Thanks for all the help!!

Mike

-----Original Message-----
From: log4net-devel-admin@lists.sourceforge.net
[mailto:log4net-devel-admin@lists.sourceforge.net] On Behalf Of Nicko
Cadell
Sent: Wednesday, December 15, 2004 12:10 PM
To: log4net-devel@lists.sourceforge.net
Subject: RE: [Log4net-devel] Log an Exception

Mike,

> I am using the second method - Debug(object,Exception).  

Ok good.

> Using PatternLayout's %m conversion character, the Exception does 
> appear to be appended to the output of the pattern.

The %m will output the rendering of the message object, whatever that
is.
As you have specified an Exception and the PatternLayout hasn't output
it (it doesn't know how to) then the appender will output the Exception
following the message line.


> 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:lin
> e 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?

Yes, log4net does get in and try to render the exception. This is does
using an IObjectRenderer and can be overridden for specified types.
This behaviour has actually been changed after 1.2 beta 8 so that by
default the exception's ToString method is used. Typically the ToString
method should output more detailed information about the exception than
the generic data log4net was extracting. It will still be possible to
override the rendering for specific exceptions using an IObjectRenderer.


> 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?

Yes. But you should consider using the latest version from CVS as in
this version it is much easier to create new patterns for the
PatternLayout and also there is a built-in ExceptionPatternConverter
which may do what you want.
 
 
> On a side note, should I post any future response to this thread on 
> the new log4net-user@logging.apache.org list?  I noticed that the 
> Sourceforge.net lists are closed.

It would probably be best to post to the log4net-user@logging.apache.org
list. I keep meaning to fully close down the sourceforge lists.

Cheers,
Nicko

> 
> 
> Thanks,
> Mike
> 
> -----Original Message-----
> From: log4net-devel-admin@lists.sourceforge.net
> [mailto:log4net-devel-admin@lists.sourceforge.net] On Behalf Of Nicko 
> Cadell
> Sent: Wednesday, December 15, 2004 8:21 AM
> To: log4net-devel@lists.sourceforge.net
> 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: log4net-devel-admin@lists.sourceforge.net
> > [mailto:log4net-devel-admin@lists.sourceforge.net] On Behalf Of 
> > Collier, Mike
> > Sent: 13 December 2004 23:42
> > To: log4net-users@lists.sourceforge.net;
> > log4net-devel@lists.sourceforge.net
> > Subject: [Log4net-devel] Log an Exception
> > 
> > How would I log an exception (type, message, and stack
> trace) using,
> > for example, the ConsoleAppender or FileAppender?  It seems
> that the
> > "%m"
> > conversion character in PatternLayout prints my log
> message, and the
> > exception type and message, but not the stack trace.
> > I see that the ExceptionLayout prints out the exception
> information.  
> > I don't see a way to use the ExceptionLayout with appenders
> like the
> > ConsoleAppender.  I could use the ExceptionLayout with the 
> > ADONetAppender though.
> > 
> > Do I need to implement my own conversion character?
> > 
> > I'm using Log4NET 1.2.0 beta 8.
> > 
> > 
> > Thanks!
> > 
> > 
> > 
> > -------------------------------------------------------
> > 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/
> > _______________________________________________
> > Log4net-devel mailing list
> > Log4net-devel@lists.sourceforge.net
> > 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/
> _______________________________________________
> Log4net-devel mailing list
> Log4net-devel@lists.sourceforge.net
> 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/
> _______________________________________________
> Log4net-devel mailing list
> Log4net-devel@lists.sourceforge.net
> 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/
_______________________________________________
Log4net-devel mailing list
Log4net-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4net-devel

Mime
View raw message