Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change logging #157

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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