Expore Program.AppName/AppShortName for logging
This commit is contained in:
		
							parent
							
								
									8de902cc79
								
							
						
					
					
						commit
						24b660f339
					
				| @ -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) | ||||||
|  | |||||||
| @ -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.AddAzureWebAppDiagnostics(); | ||||||
|             loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); |             //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); | ||||||
| 
 | 
 | ||||||
|             var pathBase = Configuration["PATH_BASE"]; |             var pathBase = Configuration["PATH_BASE"]; | ||||||
|             if (!string.IsNullOrEmpty(pathBase)) |             if (!string.IsNullOrEmpty(pathBase)) | ||||||
|  | |||||||
| @ -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) |                         .SeedAsync(context, env, settings, logger) | ||||||
|                     .Wait(); |                         .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) | ||||||
|  | |||||||
| @ -64,8 +64,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API | |||||||
|         { |         { | ||||||
|             //Configure logs |             //Configure logs | ||||||
| 
 | 
 | ||||||
|             loggerFactory.AddAzureWebAppDiagnostics(); |             //loggerFactory.AddAzureWebAppDiagnostics(); | ||||||
|             loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); |             //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); | ||||||
| 
 | 
 | ||||||
|             var pathBase = Configuration["PATH_BASE"]; |             var pathBase = Configuration["PATH_BASE"]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user