Extending the Logging block

Topics: Building and extending application blocks, Logging Application Block
Jul 30, 2009 at 9:14 PM

I’m fairly new to the enterprise library and I’m interested in knowing if anyone has any experience in extending the logging block.  We need to be able to log events to a store other than what the block comes with.  If you have done this, please share with me your experience in doing this.  Thanks!

Jul 31, 2009 at 3:42 AM

I have created several custom trace listeners, not really logging to a completely different store, just for the purpose of customizing some behaviors.  Like a custom database tracelistener for logging to a database that has a different table schemas from what is shipped out-of-the-box.  Basing on my experience when I was also new to entlib, I can say I didn't find it difficult.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 31, 2009 at 4:17 PM

Thanks Sarah for your reply.  What we are attemping to do is to log entries to a Syslog server (log to a UDP port).

Aug 3, 2009 at 6:17 AM

Hi,

I think you just need to know how to Log to your target store and then implement that code in your Custom Trace Listener.

    [ConfigurationElementType(typeof(CustomTraceListenerData))]
    public class SyslogTraceListener : CustomTraceListener
    {

        public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
        {
            //Add implementation that will save the log to SysLog Server
            //Sample: LogToSyslog(data as LogEntry);
            base.TraceData(eventCache, source, eventType, id, data);
        }

        public override void Write(string message)
        {
            throw new NotImplementedException();
        }

        public override void WriteLine(string message)
        {
            throw new NotImplementedException();
        }
    }

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 3, 2009 at 2:28 PM

Valiant,

Thank you so much for posting this reply.  We have the neccessary code to write to the syslog server, so now with your input, I think this will be very easy to do.  Thank you again for pointing us in the right direction.