Mike,
> 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?
You can just patch the 1.2 beta 8 source code if you prefer. In the
src\ObjectRenderer\DefaultRenderer.cs file in the DoRender method on
line 172 remove the whole "else if (obj is Exception)" block (4 lines).
> 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?
Using the CVS version of the source you would create a new pattern
converter that subclasses the
log4net.Layout.Pattern.PatternLayoutConverter and overrides the Convert
method.
Then to use the new pattern as part of a layout you can do the following
in the config:
<layout type="log4net.Layout.PatternLayout">
<converter>
<name value="MyConv" />
<type value="My.Converter, MyAssembly" />
</converter>
<conversionPattern value="%MyConv" />
</layout>
You don't have to modify the PatternLayout at all.
In 1.2 beta 8 you would need to modify the PatternLayout to add support
for your new pattern.
> 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?
If you need to write your own pattern then you should consider using the
source from CVS as it certainly makes this easier.
Cheers,
Nicko
> Thanks for all the help!!
>
> Mike
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Nicko Cadell
> Sent: Wednesday, December 15, 2004 12:10 PM
> To: [EMAIL PROTECTED]
> 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 [email protected] list? I noticed that the
> > Sourceforge.net lists are closed.
>
> It would probably be best to post to the
> [email protected] list. I keep meaning to fully
> close down the sourceforge lists.
>
> Cheers,
> Nicko
>
> >
> >
> > 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
> > > Collier, Mike
> > > Sent: 13 December 2004 23:42
> > > To: [EMAIL PROTECTED];
> > > [EMAIL PROTECTED]
> > > 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
> > > [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/
> > _______________________________________________
> > 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/
> > _______________________________________________
> > 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/
> _______________________________________________
> Log4net-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/log4net-devel
>