You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Serilog;
|
|
using System;
|
|
|
|
namespace Infrastructure.Web.Hosting
|
|
{
|
|
public static class IWebHostBuilderExtensions
|
|
{
|
|
public static IWebHostBuilder Config<TStartup>(this IWebHostBuilder hostBuilder) where TStartup : class
|
|
{
|
|
try
|
|
{
|
|
var configuration = new ConfigurationBuilder().Build();
|
|
Log.Logger = new LoggerConfiguration()
|
|
.ReadFrom.Configuration(configuration)
|
|
.WriteTo.Console()
|
|
.WriteTo.File("logs/log.txt", rollOnFileSizeLimit: true, fileSizeLimitBytes: 100 * 1024 * 1024, rollingInterval: RollingInterval.Infinite)
|
|
.CreateLogger();
|
|
hostBuilder
|
|
.UseSerilog()
|
|
.UseStartup<TStartup>()
|
|
.Build()
|
|
.Run();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
Log.Fatal(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
return hostBuilder;
|
|
}
|
|
}
|
|
} |