RE: Log an Exception
"Nicko Cadell" <[email protected]> Wed, 15 Dec 2004 13:20:49 -0000
| Newsgroups | gmane.comp.windows.dotnet.log4net.devel |
|---|---|
| Message-ID | <[email protected]> |
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]=20 > [mailto:[email protected]] On Behalf=20 > Of Collier, Mike > Sent: 13 December 2004 23:42 > To: [email protected];=20 > [email protected] > Subject: [Log4net-devel] Log an Exception >=20 > How would I log an exception (type, message, and stack trace)=20 > using, for example, the ConsoleAppender or FileAppender? It=20 > seems that the "%m" > conversion character in PatternLayout prints my log message,=20 > and the exception type and message, but not the stack trace. =20 > I see that the ExceptionLayout prints out the exception=20 > information. I don't see a way to use the ExceptionLayout=20 > with appenders like the ConsoleAppender. I could use the=20 > ExceptionLayout with the 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 &=20 > 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 >=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. http://productguide.itmanagersjournal.com/