Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How log to the Output window with ASP.Net vNext/5

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?

like image 718
flytzen Avatar asked May 24 '15 21:05

flytzen


1 Answers

We're adding a debug logger in beta6 https://github.com/aspnet/Logging/tree/dev/src/Microsoft.Framework.Logging.Debug

Update: https://www.nuget.org/packages/Microsoft.Extensions.Logging.Debug/1.0.0-rc1-final

like image 60
davidfowl Avatar answered Nov 01 '22 10:11

davidfowl