Asp.Net 5 (core) RC1: How to log into a file (file logging) [DNX Core 5 compatible]?

How can I enter a file in Asp.Net 5 RC1? I could not find a solution with Microsoft.Extensions.Logging. Is there any solution compatible with .Net Core 5 (DNX Core 5.0)? I also tried using Serilog, but Serilog does not yet support Core 5.

+6
source share
1 answer

To use Serilog in your ASP.NET 5 RC1 project, add the following dependencies to the project.json file:

"Serilog.Extensions.Logging": "1.0.0-rc1-final-10092", "Serilog.Sinks.RollingFile": "2.0.0-beta-465" 

Create a registrar in the Startup constructor:

 public Startup(IApplicationEnvironment appEnv) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.RollingFile(Path.Combine(appEnv.ApplicationBasePath, "log-{Date}.txt")) .CreateLogger(); } 

and add Serilog to the Startup.Configure method:

 public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddSerilog(); 
+14
source

All Articles