Browse Source

Expore Program.AppName/AppShortName for logging

pull/952/head
Miguel Veloso 6 years ago
parent
commit
24b660f339
4 changed files with 19 additions and 17 deletions
  1. +6
    -5
      src/Services/Basket/Basket.API/Program.cs
  2. +2
    -2
      src/Services/Basket/Basket.API/Startup.cs
  3. +9
    -8
      src/Services/Catalog/Catalog.API/Program.cs
  4. +2
    -2
      src/Services/Catalog/Catalog.API/Startup.cs

+ 6
- 5
src/Services/Basket/Basket.API/Program.cs View File

@ -12,7 +12,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
{ {
public class Program public class Program
{ {
private static readonly string ApplicationName = typeof(Program).Namespace;
public static readonly string AppName = typeof(Program).Namespace;
public static readonly string ShortAppName = AppName.Substring(AppName.LastIndexOf('.', AppName.LastIndexOf('.') - 1) + 1);
public static int Main(string[] args) public static int Main(string[] args)
{ {
@ -22,17 +23,17 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
try try
{ {
Log.Information("Configuring web host ({Application})...", ApplicationName);
Log.Information("Configuring web host ({Application})...", AppName);
var host = BuildWebHost(configuration, args); var host = BuildWebHost(configuration, args);
Log.Information("Starting web host ({Application})...", ApplicationName);
Log.Information("Starting web host ({Application})...", AppName);
host.Run(); host.Run();
return 0; return 0;
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Fatal(ex, "Program terminated unexpectedly ({Application})!", ApplicationName);
Log.Fatal(ex, "Program terminated unexpectedly ({Application})!", AppName);
return 1; return 1;
} }
finally finally
@ -59,7 +60,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
return new LoggerConfiguration() return new LoggerConfiguration()
.MinimumLevel.Verbose() .MinimumLevel.Verbose()
.Enrich.WithProperty("Application", ApplicationName)
.Enrich.WithProperty("Application", AppName)
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.Console() .WriteTo.Console()
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl) .WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)


+ 2
- 2
src/Services/Basket/Basket.API/Startup.cs View File

@ -181,8 +181,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{ {
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
//loggerFactory.AddAzureWebAppDiagnostics();
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
var pathBase = Configuration["PATH_BASE"]; var pathBase = Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase)) if (!string.IsNullOrEmpty(pathBase))


+ 9
- 8
src/Services/Catalog/Catalog.API/Program.cs View File

@ -14,7 +14,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
{ {
public class Program public class Program
{ {
private static readonly string ApplicationName = typeof(Program).Namespace;
public static readonly string AppName = typeof(Program).Namespace;
public static readonly string ShortAppName = AppName.Substring(AppName.LastIndexOf('.', AppName.LastIndexOf('.') - 1) + 1);
public static int Main(string[] args) public static int Main(string[] args)
{ {
@ -24,10 +25,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
try try
{ {
Log.Information("Configuring web host ({Application})...", ApplicationName);
Log.Information("Configuring web host ({Application})...", AppName);
var host = BuildWebHost(configuration, args); var host = BuildWebHost(configuration, args);
Log.Information("Applying migrations ({Application})...", ApplicationName);
Log.Information("Applying migrations ({Application})...", AppName);
host.MigrateDbContext<CatalogContext>((context, services) => host.MigrateDbContext<CatalogContext>((context, services) =>
{ {
var env = services.GetService<IHostingEnvironment>(); var env = services.GetService<IHostingEnvironment>();
@ -35,19 +36,19 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
var logger = services.GetService<ILogger<CatalogContextSeed>>(); var logger = services.GetService<ILogger<CatalogContextSeed>>();
new CatalogContextSeed() new CatalogContextSeed()
.SeedAsync(context, env, settings, logger)
.Wait();
.SeedAsync(context, env, settings, logger)
.Wait();
}) })
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { }); .MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
Log.Information("Starting web host ({Application})...", ApplicationName);
Log.Information("Starting web host ({Application})...", AppName);
host.Run(); host.Run();
return 0; return 0;
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Fatal(ex, "Program terminated unexpectedly ({Application})!", ApplicationName);
Log.Fatal(ex, "Program terminated unexpectedly ({Application})!", AppName);
return 1; return 1;
} }
finally finally
@ -73,7 +74,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
return new LoggerConfiguration() return new LoggerConfiguration()
.MinimumLevel.Verbose() .MinimumLevel.Verbose()
.Enrich.WithProperty("Application", ApplicationName)
.Enrich.WithProperty("Application", AppName)
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.Console() .WriteTo.Console()
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl) .WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)


+ 2
- 2
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -64,8 +64,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
{ {
//Configure logs //Configure logs
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
//loggerFactory.AddAzureWebAppDiagnostics();
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
var pathBase = Configuration["PATH_BASE"]; var pathBase = Configuration["PATH_BASE"];


Loading…
Cancel
Save