Is it possible to log to the All Events, Unprocessed Category and Logging Errors and Warnings

Topics: Logging Application Block
Mar 12, 2012 at 9:08 PM

I am using the logging application block.

Almost everything is working fine. Here is the setup i was trying to implement:

Couple different categories, log to a DB, working fine.

AllEvents logs to a flat file, working fine.

Unprocessed Category, log to DB and send an email.

Logging Errors and warnings, log to file, and send an email.

The problem i am running into with Unprocessed and Logging errors and warnings is that it seems like there is a precedence order where if

All events is configured then it skips Unprocessed and errors.

If all events is not configured, unprocessed works, but Errors and warnings doesn't.

If all events and unprocessed are not configured then errors and warnings works.

In the documentation I came across the following, which seems consistent with the above

" If the "all events" special log source is not configured and the "unprocessed categories" special log source is configured, and the category specified in the logEntry being logged is not defined, then the logEntry will be logged to the "unprocessed categories" special log source. If both the "all events" and "unprocessed categories" special log sources are not configured and the property LogWarningsWhenNoCategoriesMatch is set to true, then the logEntry is logged to the "logging errors and warnings" special log source."

The problem I am running into is that i like the all events because it gives me a complete log of everything that was logged if i want to see it all, while looking at the categories on their own is possible through the DB, with all events being a backup and full log.  I added the email for the unprocessed so we would be notified if someone logs to a non-configured category and then we can fix the problem.  Same with Errors and warnings, we can be notified if there is an error with the logger and handle it.

It doesn't seem like with the current configuration that I can log to the Unprocessed and Error/Warning logs without turning off the All Events.  Is this possible through a configuration or filter?  I was not able to find or figure out a way.

Thanks in advance,


Mar 13, 2012 at 6:40 AM

Your conclusions are mostly correct. 

However, even if you have AllEvents set you will still get Errors and Warnings logged you just won't get LogWarningsWhenNoCategoriesMatch.  If an exception occurs attempting to log you should still see those errors reported via the Errors and Warnings special source.

One option would be to modify the Enterprise Library source to do exactly what you want.  The change is quite simple but usually it's not desirable to modify the source code.

Since you can have multiple categories, what if you created your own "All Events" category and ensured that all LogEntry's had that category set (either through a logging facade, custom LogEntry, or a LogEntry factory, etc.)?  Then all events should be logged, plus any other categories that are also added (e.g. "General").  Then get rid of the All Events special source but keep Unprocessed Category set to handle missing categories.  All other errors will go to the errors special source. 

Randy Levy
Enterprise Library support engineer 

Mar 17, 2012 at 3:48 AM

Thanks for the info randy, appreciate it.