Newbie questions

Topics: Logging Application Block
Nov 15, 2007 at 10:44 AM
Hi everybody

I have a couple of newbie'ish questions on using the logging app block:

  • Is it possible to setup the logging configuration so all Errors are routed to the same tracelistener regardless of category? In our setup we have various components each with a unique category name but we would like to have an error logged to a certain tracelistener regardless of which component is logging the error and we would like to avoid having to list all categories in the config file (E.g. all errors should end up in the EventLog).

  • Extending on the previous question, we may also want to have all info logged to a seperate tracelistener, again regardless of component/category. This seems impossible in the configuration as the categorysource cannot contain duplicate names (multiple mentions of the same category name) and the switchValue can only be set to a single level so logging for a category can only be set to the specific value. (E.g. all errors end up in the EventLog, all warnings end up in the database and all infos end up in a rolling file)

  • Extending even more on the previous question(s) and on the switchValue in the categorysource configuration; Is it possible to specify e.g. Error and Warning to exclude all other entries (I don't know how the XML is parsed and if Error|Warning would be parsed correctly). Couldn't find any place to specify a TraceLevel to constrict the logging...

  • On a more practical note, we are running a webserver and would like to be able to write some log messages to the file system. Any recommendations on a) where to place the log file (dynamically create in a folder below the web server root or in a different location), b) How to easily handle permissions to the file so that the ASP.NET process is able to access the file (Should the folder mapped to the web server VDir be controllable by the ASPNET user account). What would be the recommended practices here (and what are tha main caveats)

Thanks in advance
Nov 15, 2007 at 12:07 PM
Hi,

Answers inline


  • Is it possible to setup the logging configuration so all Errors are routed to the same tracelistener regardless of category? In our setup we have various components each with a unique category name but we would like to have an error logged to a certain tracelistener regardless of which component is logging the error and we would like to avoid having to list all categories in the config file (E.g. all errors should end up in the EventLog).

You can accomplish this by configuring the "all events" special source with a source level of "Error" and adding an event log trace listener to it.

  • Extending on the previous question, we may also want to have all info logged to a seperate tracelistener, again regardless of component/category. This seems impossible in the configuration as the categorysource cannot contain duplicate names (multiple mentions of the same category name) and the switchValue can only be set to a single level so logging for a category can only be set to the specific value. (E.g. all errors end up in the EventLog, all warnings end up in the database and all infos end up in a rolling file)

That's correct. While the trace listeners can be configured with a filter, this configuration unfortunately is not exposed nor used by entlib.

  • Extending even more on the previous question(s) and on the switchValue in the categorysource configuration; Is it possible to specify e.g. Error and Warning to exclude all other entries (I don't know how the XML is parsed and if Error|Warning would be parsed correctly). Couldn't find any place to specify a TraceLevel to constrict the logging...

Default serialization for flags enums is "Error, Warning". This is supported by the runtime, but not by the configuration tool.

  • On a more practical note, we are running a webserver and would like to be able to write some log messages to the file system. Any recommendations on a) where to place the log file (dynamically create in a folder below the web server root or in a different location), b) How to easily handle permissions to the file so that the ASP.NET process is able to access the file (Should the folder mapped to the web server VDir be controllable by the ASPNET user account). What would be the recommended practices here (and what are tha main caveats)

I'd look for the web deployment best practices in the P&P site; I don't have a link handy though.

Regards,
Fernando