Browse Source
Merge pull request #827 from abpframework/Remove-logger-factory-configuration-from-Startup
Resolved #820 : Remove logger factory configuration from Startup
pull/839/head
Halil İbrahim Kalkan
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with
58 additions and
68 deletions
-
abp_io/src/Volo.AbpWebSite.Web/Program.cs
-
abp_io/src/Volo.AbpWebSite.Web/Startup.cs
-
abp_io/src/Volo.AbpWebSite.Web/Volo.AbpWebSite.Web.csproj
-
modules/blogging/app/Volo.BloggingTestApp/Startup.cs
-
modules/docs/app/Volo.DocsTestApp/Program.cs
-
modules/docs/app/Volo.DocsTestApp/Startup.cs
-
modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj
-
samples/BookStore/src/Acme.BookStore.Web/Startup.cs
-
templates/module/app/MyCompanyName.MyProjectName.DemoApp/Startup.cs
-
templates/mvc/src/MyCompanyName.MyProjectName.Web/Startup.cs
|
|
|
@ -1,13 +1,37 @@ |
|
|
|
using System.IO; |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Serilog; |
|
|
|
using Serilog.Events; |
|
|
|
|
|
|
|
namespace Volo.AbpWebSite |
|
|
|
{ |
|
|
|
public class Program |
|
|
|
{ |
|
|
|
public static void Main(string[] args) |
|
|
|
public static int Main(string[] args) |
|
|
|
{ |
|
|
|
BuildWebHostInternal(args).Run(); |
|
|
|
Log.Logger = new LoggerConfiguration() |
|
|
|
.MinimumLevel.Debug() //TODO: Should be configurable!
|
|
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.WriteTo.File("Logs/logs.txt") |
|
|
|
.CreateLogger(); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
Log.Information("Starting web host."); |
|
|
|
BuildWebHostInternal(args).Run(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Log.Fatal(ex, "Host terminated unexpectedly!"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
Log.CloseAndFlush(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
internal static IWebHost BuildWebHostInternal(string[] args) => |
|
|
|
@ -16,6 +40,7 @@ namespace Volo.AbpWebSite |
|
|
|
.UseContentRoot(Directory.GetCurrentDirectory()) |
|
|
|
.UseIISIntegration() |
|
|
|
.UseStartup<Startup>() |
|
|
|
.UseSerilog() |
|
|
|
.Build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -3,7 +3,6 @@ using System.Text; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Serilog; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace Volo.AbpWebSite |
|
|
|
@ -23,16 +22,6 @@ namespace Volo.AbpWebSite |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
loggerFactory |
|
|
|
.AddConsole() |
|
|
|
.AddDebug() |
|
|
|
.AddSerilog(new LoggerConfiguration() |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.Enrich.With(app.ApplicationServices.GetRequiredService<CorrelationIdLogEventEnricher>()) |
|
|
|
.WriteTo.File("Logs/logs.txt",outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] [{CorrelationId}] {Message:lj}{NewLine}{Exception}") |
|
|
|
.CreateLogger() |
|
|
|
); |
|
|
|
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); |
|
|
|
|
|
|
|
app.InitializeApplication(); |
|
|
|
|
|
|
|
@ -15,7 +15,7 @@ |
|
|
|
|
|
|
|
<ItemGroup> |
|
|
|
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.0" /> |
|
|
|
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" /> |
|
|
|
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" /> |
|
|
|
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" /> |
|
|
|
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0" /> |
|
|
|
</ItemGroup> |
|
|
|
|
|
|
|
@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Serilog; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace Volo.BloggingTestApp |
|
|
|
@ -22,14 +21,6 @@ namespace Volo.BloggingTestApp |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
loggerFactory |
|
|
|
.AddConsole() |
|
|
|
.AddDebug() |
|
|
|
.AddSerilog(new LoggerConfiguration() |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.WriteTo.File("Logs/logs.txt") |
|
|
|
.CreateLogger() |
|
|
|
); |
|
|
|
|
|
|
|
app.InitializeApplication(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,13 +1,37 @@ |
|
|
|
using System.IO; |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Serilog; |
|
|
|
using Serilog.Events; |
|
|
|
|
|
|
|
namespace Volo.DocsTestApp |
|
|
|
{ |
|
|
|
public class Program |
|
|
|
{ |
|
|
|
public static void Main(string[] args) |
|
|
|
public static int Main(string[] args) |
|
|
|
{ |
|
|
|
BuildWebHostInternal(args).Run(); |
|
|
|
Log.Logger = new LoggerConfiguration() |
|
|
|
.MinimumLevel.Debug() //TODO: Should be configurable!
|
|
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.WriteTo.File("Logs/logs.txt") |
|
|
|
.CreateLogger(); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
Log.Information("Starting web host."); |
|
|
|
BuildWebHostInternal(args).Run(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Log.Fatal(ex, "Host terminated unexpectedly!"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
Log.CloseAndFlush(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static IWebHost BuildWebHostInternal(string[] args) => |
|
|
|
@ -16,6 +40,7 @@ namespace Volo.DocsTestApp |
|
|
|
.UseContentRoot(Directory.GetCurrentDirectory()) |
|
|
|
.UseIISIntegration() |
|
|
|
.UseStartup<Startup>() |
|
|
|
.UseSerilog() |
|
|
|
.Build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Serilog; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace Volo.DocsTestApp |
|
|
|
@ -22,15 +21,6 @@ namespace Volo.DocsTestApp |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
loggerFactory |
|
|
|
.AddConsole() |
|
|
|
.AddDebug() |
|
|
|
.AddSerilog(new LoggerConfiguration() |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.WriteTo.File("Logs/logs.txt") |
|
|
|
.CreateLogger() |
|
|
|
); |
|
|
|
|
|
|
|
app.InitializeApplication(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -11,7 +11,7 @@ |
|
|
|
|
|
|
|
<ItemGroup> |
|
|
|
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.0" /> |
|
|
|
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" /> |
|
|
|
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" /> |
|
|
|
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" /> |
|
|
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="2.1.0" /> |
|
|
|
</ItemGroup> |
|
|
|
|
|
|
|
@ -2,7 +2,6 @@ |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Serilog; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace Acme.BookStore |
|
|
|
@ -21,15 +20,6 @@ namespace Acme.BookStore |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
loggerFactory |
|
|
|
.AddConsole() |
|
|
|
.AddDebug() |
|
|
|
.AddSerilog(new LoggerConfiguration() |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.WriteTo.File("Logs/logs.txt") |
|
|
|
.CreateLogger() |
|
|
|
); |
|
|
|
|
|
|
|
app.InitializeApplication(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Serilog; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace MyCompanyName.MyProjectName.DemoApp |
|
|
|
@ -22,15 +21,6 @@ namespace MyCompanyName.MyProjectName.DemoApp |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
loggerFactory |
|
|
|
.AddConsole() |
|
|
|
.AddDebug() |
|
|
|
.AddSerilog(new LoggerConfiguration() |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.WriteTo.File("Logs/logs.txt") |
|
|
|
.CreateLogger() |
|
|
|
); |
|
|
|
|
|
|
|
app.InitializeApplication(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -2,7 +2,6 @@ |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Serilog; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace MyCompanyName.MyProjectName |
|
|
|
@ -21,15 +20,6 @@ namespace MyCompanyName.MyProjectName |
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
loggerFactory |
|
|
|
.AddConsole() |
|
|
|
.AddDebug() |
|
|
|
.AddSerilog(new LoggerConfiguration() |
|
|
|
.Enrich.FromLogContext() |
|
|
|
.WriteTo.File("Logs/logs.txt") |
|
|
|
.CreateLogger() |
|
|
|
); |
|
|
|
|
|
|
|
app.InitializeApplication(); |
|
|
|
} |
|
|
|
} |
|
|
|
|