Send log entry to User Interface

Topics: Logging Application Block
Jan 22, 2008 at 10:28 AM
Hi everybody,

I have designed core framework for my project and almost implemented. I have logged each event through Logger.Write method to different categories and categories are configured through configuration file. Log entries are logged in databases and rolling flat files according to the category they belongs.

Now, I want to display all messages regardless to which category it belongs to output window, a data grid in main window. If I create custom listener for that, how can I bind my data grid with them.

Please help me to point out, Is there any event raised by Logger class when it logs the entry? so that I capture it and write the entry to the output window.

Thanks
Zeeshan
Jan 22, 2008 at 7:16 PM
Hi Zeeshan,

You can add your trace listener to the "All Events" special category, so it will get to process all entries regardless of their categories.

Now, you will need to link your listener, specified through configuration, to the grid instance. There was a related thread a while ago, and I think it was dealt with by registering a collaborator in a static variable.

Fernando
Jan 24, 2008 at 9:43 AM
Thanks Fernando,

I have created a custom trace listener with an static event. This event is raised from TraceData method of CustomTraceListener overrides in my custom trace listener. It works fine. I have attached an event handler in my GUI Form and extract LogEntry object from my CustomEventArgs.

But it seems that system performance suffers. Is it the right way what I done, or is there any work around other than that.

Thanks
Zeeshan Gulzar
Jan 24, 2008 at 12:13 PM
The performance hit depends on what you're doing in your event handler. If you're using Control.Invoke to update the UI in the right thread, which you probably should, the hit will be considerable; you may want to try an asynchronous approach like Control.BeginInvoke.

Fernando
Jan 25, 2008 at 12:42 PM
Hi Fernando,

TraceData method of CustomTraceListener is called in Main UI thread so the event handler is also executed in the same thread. Why we marshal the call? because it is already called in main thread.

Thanks
Zeeshan Gulzar