Using Visual Studio 2015 RC and ASP.Net vNext/5 beta4. I would like to output logging to the Output Window in Visual Studio when debugging or, if possible, to the console window hosting the site when using the WebListener. My Web project is built on the standard out of the box template for a Web app so has most of the default stuff in there.
In my Startup
I have the usual default
loggerfactory.AddConsole();
In my controller I inject ILoggerFactory and do something like this;
this.logger = loggerFactory.CreateLogger<ThingClass>();
this.logger.LogVerbose("Verbose");
this.logger.LogInformation("Info");
this.logger.LogError("error");
None of that gets written out to the Debug window or elsewhere - I am not really sure what AddConsole()
is supposed to achieve here?
I then tried to add Microsoft.Framework.Logging.TraceSource
to project.json
and
loggerfactory.AddTraceSource(new SourceSwitch("web-app", "Verbose"), new DefaultTraceListener());
to Startup
. That actually works - except now every log message gets written twice to the console, which is rather annoying.
I am clearly missing something fundamental here but cannot find any documentation on the new Microsoft.Framework.Logging. In fact, the most comprehensive and in-depth documentation I have been able to track down is Nicholas Blumhardt's short article here: http://nblumhardt.com/2015/05/diagnostic-logging-in-dnx-asp-net-5/.
I do understand that the framework is supposed to just be a wrapper and that I can implement my own providers as well use a range of frameworks like Serilog etc. But... for a simple application surely I should be able to log to the debug window in VS without a lot of ceremony?
答案 0 :(得分:3)
我们在beta6 https://github.com/aspnet/Logging/tree/dev/src/Microsoft.Framework.Logging.Debug
中添加了一个调试记录器更新: https://www.nuget.org/packages/Microsoft.Extensions.Logging.Debug/1.0.0-rc1-final
答案 1 :(得分:-1)
我们已成功使用:
Debug.WriteLine("Whatever I want to log to Output goes here...");
这
System.Diagnostics