You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Hsalim <hs...@msn.com> on 2008/07/30 16:11:29 UTC

Excluding stack trace from Layout

Hi,

I have tried to search for an answer here and tried to understand the
documentation but can't say I have been successful.

I'm using this configuration value for the layout pattern:

<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %newline [%thread] %newline %-5level :
%message %newline" />
</layout>

This is too much information.  I don't want the stack trace, only
exception.messge and exception.InnerException.

How do I specify that in the layout?  

Thanks in advance for helping.

Habib
-- 
View this message in context: http://www.nabble.com/Excluding-stack-trace-from-Layout-tp18734170p18734170.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Excluding stack trace from Layout

Posted by Hsalim <hs...@msn.com>.
Thanks.  I am still too new to this world and still mulling my way through.

-- 
View this message in context: http://www.nabble.com/Excluding-stack-trace-from-Layout-tp18734170p18747950.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Excluding stack trace from Layout

Posted by Freddy Gómez <gc...@gmail.com>.
Although you solved you problem by parsing the exception I'll give you an
alternative to do such a job.

You can implement a Renderer (a class which implements the interface
IObjectRenderer<http://logging.apache.org/log4net/release/sdk/log4net.ObjectRenderer.IObjectRenderer.RenderObject.html>)
for your exception and put the information you want about the exception.
Then, you just have to add a <renderer renderingClass="MyClass.MyRenderer"
renderedClass="Exception" /> element to the config file.

regards,

Fred

On Wed, Jul 30, 2008 at 12:25 PM, Hsalim <hs...@msn.com> wrote:

>
> Yann,
> Thanks for the reply.
> I guess I could do
>
> catch (Exception ex)
> {
> if (log.IsWarnEnabled)
>  log.Warn(string.Format("Error blah {0}:{1}\n{2}\n{3}", key1, key2,
> ex.Message, ex.InnerException));
> }
>
> Instead, I would prefer to pass in the exception
> log.Warn(string.Format("error blah {0}:{1}", key1,key2 ), ex);
>
> I want to use an exception layout to selectively log parts of the
> exception.
> I'll use a text file appender to log the stack trace and every gory detail
> and use an SMTP appender to semd me just the exception message and
> InnerException.  And I can change what gets logged at any time.
>
> I see from the SDK that there is an exception layout but I just cant figure
> out what I need to do.
>
> regards
> Habib
>
> --
> View this message in context:
> http://www.nabble.com/Excluding-stack-trace-from-Layout-tp18734170p18737810.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>
>

RE: Excluding stack trace from Layout

Posted by Hsalim <hs...@msn.com>.
Yann,
Thanks for the reply.
I guess I could do

catch (Exception ex)
{
if (log.IsWarnEnabled)
 log.Warn(string.Format("Error blah {0}:{1}\n{2}\n{3}", key1, key2,
ex.Message, ex.InnerException));				
}

Instead, I would prefer to pass in the exception 
log.Warn(string.Format("error blah {0}:{1}", key1,key2 ), ex);

I want to use an exception layout to selectively log parts of the exception.
I'll use a text file appender to log the stack trace and every gory detail
and use an SMTP appender to semd me just the exception message and
InnerException.  And I can change what gets logged at any time.

I see from the SDK that there is an exception layout but I just cant figure
out what I need to do.

regards
Habib

-- 
View this message in context: http://www.nabble.com/Excluding-stack-trace-from-Layout-tp18734170p18737810.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: Excluding stack trace from Layout

Posted by Yann Luppo <Ya...@fox.com>.
I believe the place holder "%message" refers to the data sent when you do log.Debug(message). I think it's more about how you build the message in the logger that matter in your case. Try to send us your logger call maybe. 

Yann 

-----Original Message-----
From: Hsalim [mailto:hsalim@msn.com] 
Sent: Wednesday, July 30, 2008 7:11 AM
To: log4net-user@logging.apache.org
Subject: Excluding stack trace from Layout


Hi,

I have tried to search for an answer here and tried to understand the
documentation but can't say I have been successful.

I'm using this configuration value for the layout pattern:

<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %newline [%thread] %newline %-5level :
%message %newline" />
</layout>

This is too much information.  I don't want the stack trace, only
exception.messge and exception.InnerException.

How do I specify that in the layout?  

Thanks in advance for helping.

Habib
-- 
View this message in context: http://www.nabble.com/Excluding-stack-trace-from-Layout-tp18734170p18734170.html
Sent from the Log4net - Users mailing list archive at Nabble.com.