Browse Source

Added serilog logging to blazor server side.

pull/8074/head
Halil İbrahim Kalkan 6 years ago
parent
commit
1e1aed74d0
  1. 1
      templates/app/aspnet-core/.gitignore
  2. 39
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server/Program.cs

1
templates/app/aspnet-core/.gitignore

@ -258,3 +258,4 @@ src/MyCompanyName.MyProjectName.IdentityServer/Logs/*
src/MyCompanyName.MyProjectName.HttpApi.Host/Logs/*
src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/Logs/*
src/MyCompanyName.MyProjectName.DbMigrator/Logs/*
src/MyCompanyName.MyProjectName.Blazor.Server/Logs/*

39
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server/Program.cs

@ -1,13 +1,45 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
namespace MyCompanyName.MyProjectName.Blazor.Server
{
public class Program
{
public static void Main(string[] args)
public static int Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
Log.Logger = new LoggerConfiguration()
#if DEBUG
.MinimumLevel.Debug()
#else
.MinimumLevel.Information()
#endif
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Async(c => c.File("Logs/logs.txt"))
#if DEBUG
.WriteTo.Async(c => c.Console())
#endif
.CreateLogger();
try
{
Log.Information("Starting web host.");
CreateHostBuilder(args).Build().Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly!");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
@ -16,6 +48,7 @@ namespace MyCompanyName.MyProjectName.Blazor.Server
{
webBuilder.UseStartup<Startup>();
})
.UseAutofac();
.UseAutofac()
.UseSerilog();
}
}

Loading…
Cancel
Save