How can I log to file in Asp.Net 5 RC1? I couldn't find any solution with Microsoft.Extensions.Logging. Is there any solution which is compatible with .Net Core 5 (DNX Core 5.0)? I also was trying to use Serilog but Serilog doesn't support core 5 yet.
To use Serilog in your ASP.NET 5 RC1 project, add the following dependencies in your project.json file:
"Serilog.Extensions.Logging": "1.0.0-rc1-final-10092",
"Serilog.Sinks.RollingFile": "2.0.0-beta-465"
Create the logger 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 in the Startup.Configure
method:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With