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?
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:
One way to achieve this would be to implement your own implementation of the ILoggerFactory and ILogger classes. ie
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 ie a database logger
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.