4

On my production, I don't want to have log entry with severity Verbose (or Debug). I need only the info, error etc. What is the right method to enable and disable logging (the debug entries)?

I did some research and one possibility is to use Custom Filter class to enable and disable all logs with severity "verbose". But When deploying application on production, what is the right way to enable and disable?

3 Answers 3

5

You don't have to get in to custom filters. Assuming you have one category defined then you just need to set the Severity or SourceLevel that you want to log. It sounds like you want to set the SourceLevel to Information which "allows Critical, Error, Warning, and Information events through".

In config this would look something like:

<categorySources>
    <add switchValue="Information" name="General">
        <listeners>
            <add name="Formatted EventLog TraceListener" />
        </listeners>
    </add>
</categorySources>

In terms of best practices there is no one right way. Usually you would probably enable the logging of as little information as required to properly support the application. This will depend on the type of logging you've placed in your application. For most applications this would probably be Information or Warning. However, other factors could influence this including current application stability, operational requirements etc.

3
  • 2
    Details of possible filtering is well described in thejoyofcode.com/… Commented Jan 20, 2012 at 11:20
  • @MichaelFreidgeim, I like the diagram -- it's easy to see the flow.
    – Randy Levy
    Commented Jan 20, 2012 at 15:07
  • Note that the 'name' attribute in the 'add' element within 'categorySources' is not intended to hold the name of the categorySource that is being added but rather the name of the category that it will route event entries from. i.e. 'General' is the name of a category in the example above - not the name of the categorySource. Commented Nov 29, 2012 at 13:19
3

You can set your logging level in your config file, that way, should you need it in production for whatever reason, you can switch it on at any time.

2
  • 1
    It's definitely not the only way. But it is very common. And having an automated way to apply configuration changes per environment is a best practice. Manually changing the configuration values wouldn't be, but the idea of changing values in web.config per environment is a perfectly valid solution.
    – Jon Adams
    Commented Feb 22, 2011 at 22:01
  • And can you explain me the automated way of applying configuration changes? What I am look for is a way to enable and disable "DEBUG" logging for a deployed application. When some issue occurs, add a new patch, we need to keep the DEBUG on for a few hours. Commented Feb 23, 2011 at 5:31
0

You can set different levels in web.config.release and web.config.debug files. You can read more here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.