Accessing CustomTraceListener Attributes from outside of customTraceListener class

Topics: Enterprise Library Core, Logging Application Block
Dec 9, 2010 at 2:26 PM

Good morning,

I have implemented a custom logging class that inherits from CustomTraceListener. It writes to an XML file using and associated custom formatter that is derived from LogFormatter. During the initial write to the log file, the custom listener creates a unique file name for the log file. Basically, it reads the output path from its list of attributes and uses the date and time of the first entry to name the log file.  All of this is working fine, except...

My logging workflow dictates that, upon completion of the final log entry, my log file be shipped to a common location on our network for long term storage. This is basically a file copy, but I can't copy the file if I don't know the name.

What I'm up against is that I don't see a way to get that value out of that class and make it available to my application. I can store it in the customLogWriter as a member variable, but I don't see a way to get access to it.

Am I missing, or have I overlooked something?



Dec 10, 2010 at 6:33 AM

There could be more much better approach though here's my personal opinion. How about having it part of your LogEntry object, maybe as an extended property or you can extend the LogEntry class itself and add a specific member variable (filename). By doing this, at the application level you can already define the filename of your log and sure that you can refer to it when you need it.  Unless there is a specific requirement that it should be in the CustomTraceListener, I may be missing something :-) Anyway, hope this helps.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.