Logging Rules

Topics: Logging Application Block
Oct 8, 2007 at 1:16 PM
Hi, i need help to achieve my logging configuration.
I need to log everything to a database trace listener and all critical error to a local file.

To do this, I set two special sources :
- Database Trace Listener in "All Event" (with SourceLevels = All)
- FlatFile Trace Listener in "Logging Errors & Warnings" (with SourceLevels = Critical)

But the trace.log file is never created. When I switch FlatFile Trace Listener SourceLevels to "All", nothing changed.
I try to delete my Database Trace Listener to check if Special Sources were exclusive but no. In fact I don't understand how to use "Logging Errors & Warnings" special sources.
I tried to move FlatFile Trace Listener to "All Event" and this listener work fine, but everything go to trace.log and I only want Critical.

Any Ideas ?
Thanks

Ivan
Oct 9, 2007 at 12:20 PM
Hi,

The "Logging Errors & Warnings" is used for logging events that occurred inside the logging block while processing external requests (e.g. tried to log to the event log but couldn't do it).

I don't think you will be able to get the exact behavior you're looking for. While .NET trace listeners do have filtering at the listener level, which is be necessary for your scenario, this filtering is not exposed by EntLib's configuration. You can get very close to this by taking advantage of the "multi-category" logging methods, and set up a source for logging all critical errors; you would have to make sure all logging calls include this category of course.

Hope this helps,
Fernanndo
Oct 9, 2007 at 1:05 PM
Yeah thank you for the "Logging Errors & Warnings" special sources explanation !
I'm going to use "multi-category" methods to filter critical errors.

Ivan
Oct 9, 2007 at 10:21 PM
can someone help me on how to log to an XML file using the XML trace listener in EL v 3.1?
Oct 11, 2007 at 1:29 PM
Hi,


dshah wrote:
can someone help me on how to log to an XML file using the XML trace listener in EL v 3.1?


Are you facing a particular issue? How far did you get into using it?
You can look at the Logging QuickStart for an example on how to use logging; using the Xml trace listener should only require configuring this trace listener using the configuration tool.

Fernando
Oct 11, 2007 at 2:56 PM
Hey Fernando,

Thanks for your reply, i actually got as far as setting up the XML trace listener in the EL Config tool and i saw that the file that it wants to write to is called trace-xml.log I think it does this because it might be faster to write xml to a text file instead of opening up an XML file each time to append the new node. So i wanted to see the log in IE in XML format so i renamed the file to trace.xml and opened it up in IE. It displays fine with only one log entry but when there are two or more it shows an error saying:

Only one top level element is allowed in an XML document. Error processing resource 'file:///C:/Documents and Settings/DSha...

</Message><Categories><String>Tracing-XML</String></Categories><Priority>0</Priority&...


I dont know if i am setting things up properly. Here is what i did in EL Config Tool:

1.) I added the Exception Handling Block to my application
2.) Then I added an Exception Policy named XML_File Policy
3.) Then I added an Exception Type to my Policy of type System.Exception
4.) Then i added a Logging Handler to my Exception Type which automatically added the Logging App Block to my application
5.) I set up a new Category under Category Sources called Tracing-XML
6.) I added an XML Trace Listener under Trace Listeners and the filename is called trace-xml.log by default
7.) I added this trace listener to my Tracing-XML category
8.) I specified to use the Tracing-XML category for my Logging Handler for the XML_File policy i created above.
9.) Also for the logging handler i chose the TextExceptionFormatter but also had the option of choosing the XMLExceptionFormatter.

Under my Formatters in the Logging Application Block i have the Default Formatter which has the following template:

Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}

What i dont understand is that i can not specify what formatter to use under the XML Trace Listener but for some reason it uses the Default formatter automatically. Can you please tell me if i am doing something wrong here? Thanks so much for any help you can provide.

Devang