From 5c2b145ec2463bd4f8cd3affa5b6dd6f40043b08 Mon Sep 17 00:00:00 2001 From: Miguel Veloso Date: Thu, 14 Mar 2019 16:50:44 +0000 Subject: [PATCH] Commented out local configuration, to avoid exception --- src/Web/WebStatus/Program.cs | 42 ++++++++++++++++++++++++++++-- src/Web/WebStatus/WebStatus.csproj | 6 ++--- src/Web/WebStatus/appsettings.json | 10 +------ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/Web/WebStatus/Program.cs b/src/Web/WebStatus/Program.cs index d2de3ceae..91d004ae2 100644 --- a/src/Web/WebStatus/Program.cs +++ b/src/Web/WebStatus/Program.cs @@ -1,17 +1,19 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Serilog; using System; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Reflection; namespace WebStatus { public class Program { - public static readonly string Namespace = typeof(Program).Namespace; public static readonly string AppName = Namespace; + public static readonly string Namespace = typeof(Program).Namespace; public static int Main(string[] args) { @@ -24,6 +26,8 @@ namespace WebStatus Log.Information("Configuring web host ({ApplicationContext})...", AppName); var host = BuildWebHost(configuration, args); + LogPackagesVersionInfo(); + Log.Information("Starting web host ({ApplicationContext})...", AppName); host.Run(); @@ -83,5 +87,39 @@ namespace WebStatus return builder.Build(); } + + private static string GetVersion(Assembly assembly) + { + try + { + return $"{assembly.GetCustomAttribute()?.Version} ({assembly.GetCustomAttribute()?.InformationalVersion.Split()[0]})"; + } + catch + { + return string.Empty; + } + } + + private static void LogPackagesVersionInfo() + { + var assemblies = new List(); + + foreach (var dependencyName in typeof(Program).Assembly.GetReferencedAssemblies()) + { + try + { + // Try to load the referenced assembly... + assemblies.Add(Assembly.Load(dependencyName)); + } + catch + { + // Failed to load assembly. Skip it. + } + } + + var versionList = assemblies.Select(a => $"-{a.GetName().Name} - {GetVersion(a)}").OrderBy(value => value); + + Log.Logger.ForContext("PackageVersions", string.Join("\n", versionList)).Information("Package versions ({ApplicationContext})", AppName); + } } } \ No newline at end of file diff --git a/src/Web/WebStatus/WebStatus.csproj b/src/Web/WebStatus/WebStatus.csproj index e898a3a2e..ea2cfb711 100644 --- a/src/Web/WebStatus/WebStatus.csproj +++ b/src/Web/WebStatus/WebStatus.csproj @@ -11,9 +11,9 @@ - + - + @@ -24,7 +24,7 @@ - + diff --git a/src/Web/WebStatus/appsettings.json b/src/Web/WebStatus/appsettings.json index 9ff359423..25b82f721 100644 --- a/src/Web/WebStatus/appsettings.json +++ b/src/Web/WebStatus/appsettings.json @@ -1,5 +1,5 @@ { - "HealthChecks-UI": { + "HealthChecks-UI-commented-out": { "HealthChecks": [ { "Name": "Ordering HTTP Check", @@ -70,14 +70,6 @@ "Uri": "http://localhost:5121/hc" } ], - "Webhooks": [ - { - "Name": "", - "Uri": "", - "Payload": "", - "RestoredPayload": "" - } - ], "EvaluationTimeOnSeconds": 10, "MinimumSecondsBetweenFailureNotifications": 60 },