8

So I have this in my Startup.cs by default:

loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); 

How do I see the console the loggerFactory is adding? I can see the logging info in the Debug output window, but it's very muddled with the rest of automatic debug information and hard to find.

Is there a way to view the logger console or if not, a way to display the information that only I log in Output?

2 Answers 2

3

To display less clutter generated by the Framework in the Debug Window you can select which aspects are logged.

In particular I turn off "Module Load Messages" as that is the bulk of the messages (in VS 2015). Also, "Thread Exit Messages" are another to consider turning off.

Tools -> Options -> Debugging -> Output Window:

"Module Load Messages" logging options in Visual Studio 2015

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

Comments

1

One way to achieve this would be to implement your own implementation of the ILoggerFactory and ILogger classes. i.e.

public class MyLoggerFactory : ILoggerFactory {...} public class MyConsoleLogger : ILogger {...} 

You can take a look at the implementations of Microsoft's built in logging and create your own based on these as needed: https://github.com/aspnet/Logging/tree/dev/src/Microsoft.Extensions.Logging

This will allow you to override the default Log methods and even create your own overrides which identity it as user logged vs system logged or whatever you need from it.

Once you have your own implementations you can then register it like the following:

//Register logging var loggerConfig = Configuration.GetValue("Logging", new MyLoggingConfig()); var loggerFactory = new MyLoggerFactory(loggerConfig); services.AddSingleton(typeof(ILoggerFactory), loggerFactory); services.AddLogging(); 

I have done this in a test project of mine and it works well for us. You can also create other implementations of logging if needed i.e a database logger

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.