logging - How to register an EventSource etw provider C# and capture the output to a log file.? -
i created "logger" class derives base class eventsource (event provider). used instrument application. now, view trace messages logged application use perfview gui tool - first register event provider "*logger" , start collection process through tool. once collection done can view logged events.this works fine, need automate process.
when trying automate process faced 2 issues:
- how register event provider (preferably using c# libraries or microsoft provided cli tools[don't want use third party tools or libraries this.])
- how collect logged events etl file using tools logman (or other command line tools).
i have provided application source code below (the code basic , straight forward.):
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.diagnostics.tracing; using system.threading; namespace eventlogging { class program { static void main(string[] args) { logger log = logger.getlogger(); (int = 0; < 100000; i++) { log.writeerror("logging serious error",i); log.writewarning("logging warning",i); } } } /// <summary> /// logger writes instance. /// /// </summary> class logger : eventsource { /// <summary> /// /// </summary> static private logger _log; /// <summary> /// 1 instance of logger can created. /// </summary> public static logger getlogger(){ if (_log == null) return (_log = new logger()); else return _log; } private logger() : base() { } [event(101,message="application failure message: {0}",level=eventlevel.error)] public void writeerror(string message1,int value){ writeevent(101, message1,value); } [event(102,message="application warning message: {0}",level=eventlevel.warning)] public void writewarning(string message,int value) { writeevent(102, message,value); } } }
microsoft traceevent library enables capture , process etw traces. understands eventsource, there no reason register anything. see here, here , here.
Comments
Post a Comment