[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4net-user
Subject:    Writing custom errormessages
From:       "Ivar Kvanum Sund" <ivar.sund () itsolutions ! no>
Date:       2004-06-11 9:13:30
Message-ID: NEEDIAEGKHHCEALIFDBLEEBKCDAA.ivar.sund () itsolutions ! no
[Download RAW message or body]

Hi.

I have subclassed the LayoutSkeleton class successfully so that I can format
my own custom log information.

Is there any way to get the exception object? I see that it is stored in the
LoggingEvent as m_thrownException, but it is not accessable. I need this
object to be able to retrieve properties within the exception, without
touching the Message property.
I have attaced a small example, but if there are other better ways of doing
this, please let me know.


Example:
class TestException : ApplicationException
{
	private string myProperty1;
	private string myProperty2;

	public TestException( string message, string myProperty1, string
myProperty2 ) : base(message)
	{
		this.myProperty1 = myProperty1;
		this.myProperty2 = myProperty2;
	}
}

class CustomLayout : LayoutSkeleton
{
	...
	public override string Format( log4net.spi.LoggingEvent loggingEvent )
	{
		StringBuilder msg = new StringBuilder();
		...
		if ( exception is TestException )
		{
			msg.Append( "MyProperty1: " + exception.MyProperty1 );
			msg.Append( "MyProperty2: " + exception.MyProperty2 );
		}
		...
		return msg.ToString();
	}
}





Best regards

Ivar Kvanum Sund
Software Engineer

----------------------------------------------------------------------

it:solutions, O. J. Brochs gate 16B, P.B. 2686, N-5836 Bergen, Norway
+47 98 28 37 75 (office)
+47 95 76 12 51 (cellular phone)
+47 55 23 60 71 (fax)

ivar.sund@itsolutions.no

Subscribe to the it:solutions newsletter at http://www.itsolutions.no

----------------------------------------------------------------------

CONFIDENTIALITY NOTICE:

The content of this e-mail is intended solely for the use of the individual
or entity to whom it is addressed. If you have received this communication
in error, be aware that forwarding it, copying it or in any way disclosing
its content to any other person, is strictly prohibited. If you have
received this communication in error, please notify the author by replying
to this e-mail immediately.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06.06.2004

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic