Skip to content

Commit

Permalink
Merge pull request #157 from bcgov/change-logging
Browse files Browse the repository at this point in the history
Change logging
  • Loading branch information
pbolduc authored Sep 4, 2020
2 parents 21e37b4 + 8728ea9 commit 3c6caea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
30 changes: 9 additions & 21 deletions api/src/BcGov.Malt.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using BcGov.Malt.Web.Models.Configuration;
using BcGov.Malt.Web.Services;
Expand Down Expand Up @@ -58,29 +57,17 @@ public static async Task<int> Main(string[] args)
/// <summary>
/// Creates the host builder.
/// </summary>
public static IHostBuilder CreateHostBuilder(string[] args)
private static IHostBuilder CreateHostBuilder(string[] args)
{
var builder = Host.CreateDefaultBuilder(args)
.UseSerilog(ConfigureSerilogLogging)
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); })
.ConfigureAppConfiguration((hostingContext, config) =>
{
// Added before AddUserSecrets to let user secrets override environment variables.
config.AddEnvironmentVariables();

var env = hostingContext.HostingEnvironment;
if (env.IsDevelopment())
{
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
config.AddUserSecrets(appAssembly, optional: true);
}
});
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });

return builder;
return builder;
}

private static ILogger GetProgramLogger(string[] args)
{
{
// configure the program logger in the same way as CreateDefaultBuilder does
string environmentName = GetEnvironmentName();

Expand Down Expand Up @@ -124,7 +111,7 @@ static string GetEnvironmentName()

return logger;
}

private static void ConfigureSerilogLogging(HostBuilderContext hostingContext, LoggerConfiguration loggerConfiguration)
{
loggerConfiguration
Expand Down Expand Up @@ -152,14 +139,15 @@ private static void ConfigureSerilogLogging(HostBuilderContext hostingContext, L
messageHandler: new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
},
});
#pragma warning restore CA2000 // Dispose objects before losing scope
renderTemplate: false);
}
}

private static async Task GetAccessTokensAsync(ILogger logger, IServiceProvider services)
{
// use a logger with context
logger = logger.ForContext<IAccessTokenLoader>();

try
{
Expand Down Expand Up @@ -190,7 +178,7 @@ private static async Task GetAccessTokensAsync(ILogger logger, IServiceProvider
{
logger.Error("Error fetching {ErrorCount} of total {AccessTokenCount} access tokens, process took {ElapsedMilliseconds} milliseconds",
exceptionCount,
results.Count,
results.Count,
milliseconds);

}
Expand Down
5 changes: 3 additions & 2 deletions maltd-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"ci-test": "cross-env CI=true jest --env=jsdom --testResultsProcessor=jest-sonar-reporter --update-snapshot --runInBand --coverage",
"cy:run": "cypress run"
"cy:run": "cypress run",
"format-staged": "pretty-quick --staged"
},
"jest": {
"setupFilesAfterEnv": [
Expand Down Expand Up @@ -108,7 +109,7 @@
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged",
"pre-commit": "npm run format-staged",
"pre-push": "npx eslint ."
}
}
Expand Down

0 comments on commit 3c6caea

Please sign in to comment.