tags:

views:

81

answers:

1

Hello all,

My application uses the Trace object to log information. The information is captured in a file with the TextWriterTraceListener and it works perfectly. However, I would like to add another TraceListerner which will record the information to a Web Service. In other words, I need an HttpTraceListener. Moreover, I need something intelligent, I wouldn’t like to see a HTTP request for every log entry.

How would you build such thing? I know I have to inherit TraceListener (the documentation is somewhat cryptic...) but does anybody have an idea if a HttpTraceListener already exist? I don't want to reinvent the wheel...

Thanks!

+1  A: 

Because of your requirements about variable logging, i.e. not issuing a request for every entry, you will most certainly need to create your own listener.

Per MSDN docs on TraceListener (http://msdn.microsoft.com/en-us/library/system.diagnostics.tracelistener(VS.80).aspx)

"Inherit from this class to implement a custom listener for the Debug and Trace classes. At a minimum, you must implement the Write and WriteLine methods. Additionally, you can implement the Fail, Close and Flush methods."

I would start with:

  1. Inherit from TraceListener.
  2. Implement the Write/WriteLine methods
  3. Add your logic in Write to submit the request to a web service. WriteLine simply appends a line terminator, if you use the base class implementation.
  4. Override Fail/Close/Flush as needed for your application.

Those 5 methods will give you all the access you need to implement your listener.

jro