7

I used to use DebugView.exe to view Debug messages from my web applications in classic ASP.Net. I just need to use Debug.WriteLine("Message to display"); and it shows in the window on the DebugView. I can also trace/view messages on the Production Server by using that method.
Eg. http://woutercx.com/2013/08/23/debugview-tool-how-it-saved-my-day/

In ASPNetCore, I am trying to do the samething by using the Logger. I can view all the loggings correctly in VS2015 Output Window. But I couldn't see it anymore in DebugView software. And those logging messages are missing with other thousand of logging lines from MVC & ASP Engines and it's really difficult to view the messages which I only want to view.

Please see as an example in the picture below:

enter image description here

Is there anyway to view those logging messages in DebugView in ASP.Net Core? Or anyway to get rid of those extra loggings in ASPNet.Core?

I did try to exclude those lines in Startup.cs... but no success yet.

loggerFactory.AddConsole((cat, level) => cat.StartsWith("WindowsAuthentication.") && level == LogLevel.Debug);
loggerFactory.AddDebug(LogLevel.Debug);

1 Answer 1

5

It looks like the source only calls Debug.WriteLine if the Debugger is attached, meaning it is a no-op in production (unless you're remote debugging with a debugger attached). See the relevant source lines on GitHub at https://github.com/aspnet/Logging/blob/master/src/Microsoft.Extensions.Logging.Debug/DebugLogger.cs#L48-L50. It says:

    public bool IsEnabled(LogLevel logLevel)
    {
        // If the filter is null, everything is enabled
        // unless the debugger is not attached
        return Debugger.IsAttached &&
            logLevel != LogLevel.None &&
            (_filter == null || _filter(_name, logLevel));
    }

I suspect you could write your own Debug Logger Provider that looks almost identical to what is in GitHub but have the IsEnabled method disregard the Debugger.IsAttached check.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.