c# - How to use custom trace listener to log traces in .net -


i have come across link http://www.codeproject.com/articles/447238/advanced-tracing#_comments. , author did quite nice job of creating custom listener logs database. while researching more on tracing/logging read (from here https://blogs.msdn.microsoft.com/bclteam/2005/09/20/a-tracing-primer-part-ii-b-mike-rousos/) trace source calls following methods when needs trace through listener.

    void traceevent(traceeventcache eventcache, string source, traceeventtype eventtype, int id)     void traceevent(traceeventcache eventcache, string source, traceeventtype eventtype, int id, string message)     void traceevent(traceeventcache eventcache, string source, traceeventtype eventtype, int id, string format, params object[] args)     void tracedata(traceeventcache eventcache, string source, traceeventtype eventtype, int id, object data)     void tracedata(traceeventcache eventcache, string source, traceeventtype eventtype, int id, params object[] data)     void tracetransfer(traceeventcache eventcache, string source, int id, string message, guid relatedactivityid) 

and these methods (barring 1 or 2) has been overridden (all of them public , tracetransfer calls writeline method, since msdn blog says these traceevent/data/transfer methods internally call write/writeline methods) author of custom trace listener (in first link codeproject.com). want test custom listener see how behaves. in real life don't know how trace source call traceevent (with multiple overloads) , tracetransfer() methods trace through custom listener. though know can create instance of trace source as

tracesource ts = new tracesource("myapp"); ts.listeners.add(new dbtracelistener); 

and add custom listener (as in code above) question remains in how trace source call traceevent/tracetransfer methods (written in dbtracelistener) trace through custom listener.

in other words don't know how use custom listener in application log traces. appreciated.

an easy way add trace listener using trace.listeners.add(). example, add textwritertracelistener:

var listener = new textwritertracelistener("e:\\blah.txt"); trace.listeners.add(listener); trace.autoflush = true; trace.writeline("test!"); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -