From b976035ee6839f97f35dd5e67b686c8bc6a766db Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 26 Nov 2023 14:18:05 +0000 Subject: [PATCH] Configure logging with appsettings.json Use appsettings.json to configure logging instead of code. --- src/LondonTravel.Skill/AlexaFunction.cs | 29 +------------------ .../LondonTravel.Skill.csproj | 1 + src/LondonTravel.Skill/appsettings.json | 10 +++++++ 3 files changed, 12 insertions(+), 28 deletions(-) create mode 100644 src/LondonTravel.Skill/appsettings.json diff --git a/src/LondonTravel.Skill/AlexaFunction.cs b/src/LondonTravel.Skill/AlexaFunction.cs index 63665d3e..45d51dca 100644 --- a/src/LondonTravel.Skill/AlexaFunction.cs +++ b/src/LondonTravel.Skill/AlexaFunction.cs @@ -7,7 +7,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; -using LogLevel = Microsoft.Extensions.Logging.LogLevel; namespace MartinCostello.LondonTravel.Skill; @@ -103,12 +102,7 @@ public Task InitializeAsync() /// The service collection to configure. protected virtual void ConfigureServices(IServiceCollection services) { - services.AddLogging((builder) => - { - builder.SetMinimumLevel(LogLevel.Information) - .AddFilter(FilterLogs) - .AddJsonConsole(); - }); + services.AddLogging((builder) => builder.AddJsonConsole()); services.AddHttpClients(); @@ -140,27 +134,6 @@ protected virtual void Dispose(bool disposing) } } - /// - /// Filters the Lambda logs. - /// - /// The name of the log. - /// The log level. - /// - /// to log the message; otherwise . - /// - private static bool FilterLogs(string name, LogLevel level) - { - if (level < LogLevel.Warning && - (name.StartsWith("System.", StringComparison.Ordinal) || - name.StartsWith("Microsoft.", StringComparison.Ordinal) || - name.StartsWith("Polly", StringComparison.Ordinal))) - { - return false; - } - - return true; - } - /// /// Creates the to use. /// diff --git a/src/LondonTravel.Skill/LondonTravel.Skill.csproj b/src/LondonTravel.Skill/LondonTravel.Skill.csproj index a6319344..8fc11217 100644 --- a/src/LondonTravel.Skill/LondonTravel.Skill.csproj +++ b/src/LondonTravel.Skill/LondonTravel.Skill.csproj @@ -29,5 +29,6 @@ + diff --git a/src/LondonTravel.Skill/appsettings.json b/src/LondonTravel.Skill/appsettings.json new file mode 100644 index 00000000..b6040f6b --- /dev/null +++ b/src/LondonTravel.Skill/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Polly": "Warning", + "System": "Warning" + } + } +}