Fluent Configuration API - custom trace listener

Topics: Exception Handling Application Block, Logging Application Block
Nov 18, 2010 at 7:35 PM

Hello,

I have some problems configuring custom listener for Logging application block with Fluent configuration API.

I would like to log all errors on my web applications to one depository via web services.

For demo purposes lets say that this is my custom trace listener:

[ConfigurationElementType(typeof(CustomTraceListenerData))]
public class WebServiceTraceListener : CustomTraceListener
{
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { throw new NotImplementedException(); }
public override void Write(string message) { throw new NotImplementedException(); }
public override void WriteLine(string message) { throw new NotImplementedException(); }
}

So trace listener should throw exception. Now, my configuration settings in HTTPModule looks like this:

builder.ConfigureInstrumentation().EnableLogging();
builder.ConfigureLogging()
.WithOptions
.SpecialSources.AllEventsCategory
.SendTo.FlatFile("Security Log File").ToFile("security.log")
.SendTo.Custom<WebServiceTraceListener>("WebServiceTraceListener")
;

FlatFile creates security.log file with exception details, but custom trace listener never fires NotImplementedException.. Can someone please tell me what's wrong with my code?

Thank you..

 

Nov 18, 2010 at 10:39 PM

Exceptions thrown within the Logging Application Block are being swallowed and handled internally.  That is how it is designed.

 

Sarah Urmeneta
Global Technologies & Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 18, 2010 at 10:47 PM

Hello Sarah, thank you for your reply..

Now if I understood you correctly, my custom trace listener is triggering NotImplementedException but its being swallowed by L.A.B., so my configuration with Fluent configuration API is correct and if I implement call to webservice in Write method within WebServiceTraceListener everything should work just fine ?

Nov 18, 2010 at 10:58 PM

I just tested it and it works fine, silly me..

Thank You ..

Nov 18, 2010 at 11:02 PM

Glad it works :)

 

Sarah Urmeneta
Global Technologies & Solutions
Avanade, Inc.
entlib.support@avanade.com