Logging different messages to different files

Topics: Using
Jul 2, 2014 at 11:25 PM
I am attempting to use SLAB in a base class that logs to a flat file that has a filename based on the derived class. All seemed fine until I tested simultaneous logging from two different assemblies (a console app is calling a class library). Two files are indeed created but any log message from either assembly is saved to both files. If I look at each of the EventListener variables while debugging, I do see the two different filenames. After some thought, it sort of makes sense why this is happening - the two assemblies are writing the same events from the same custom EventSource class and therefore, both file EventListeners are listening for the same events. They're just writing all events to their respective files.

OK, so now that I can seemingly justify why this is happening, the real question is how can I achieve what I initially set out to do? That is, I want to log discrete messages to different log files based on the assembly of the derived class. They are, in all respects, writing the same eventid and keyword. I thought of creating new Tasks and/or OpCodes or does the new ActivityId satisfy my requirement? I'm not familiar with the latter. The only thing I want to avoid is having to create a master list of every assembly that will be logging. However, I do understand this is Semantic logging. Has anyone else run into this or is everyone just dumping all system-wide logs to a central sink like SQL then disseminate the logs using some reader that filters based on eventids, keywords, etc? Any help is greatly appreciated. I would hope that the time I spent going down this path wasn't wasted.
Jul 3, 2014 at 12:22 AM
I'd recommend that if you have this scenario, then you could potentially be having 2 different events, with their own eventIds (and potentially different keywords, to allow filtering in and out easily).

Having said that, you can achieve what you want by using Rx, and having an ObservableEventListener, where you filter some events (based on an extra argument that you pass in, I suppose, depending the class used for logging), and then you send it to a particular sink. You can download the QuickStarts from here: http://www.microsoft.com/en-us/download/details.aspx?id=38789

There's 2 QuickStarts that show how to use Rx with SLAB, although none of them is your exact scenario, but it might be enough to understand it.