diff --git a/benchmarks/Benchmarks.csproj b/benchmarks/Benchmarks.csproj index 1e8b227f3c..9f3320575b 100644 --- a/benchmarks/Benchmarks.csproj +++ b/benchmarks/Benchmarks.csproj @@ -10,6 +10,6 @@ - + diff --git a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj index 94e2a404a9..e588c81b4e 100755 --- a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj +++ b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj @@ -25,9 +25,4 @@ - - - - - diff --git a/src/Examples/JsonApiDotNetCoreExample/Startup.cs b/src/Examples/JsonApiDotNetCoreExample/Startup.cs index 378a948a61..2c7574e1a2 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Startup.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Startup.cs @@ -28,7 +28,7 @@ public Startup(IHostingEnvironment env) public virtual IServiceProvider ConfigureServices(IServiceCollection services) { var loggerFactory = new LoggerFactory(); - loggerFactory.AddConsole(LogLevel.Trace); + loggerFactory.AddConsole(LogLevel.Warning); services .AddSingleton(loggerFactory) @@ -57,7 +57,6 @@ public virtual void Configure( context.Database.EnsureCreated(); loggerFactory.AddConsole(Config.GetSection("Logging")); - loggerFactory.AddDebug(); app.UseJsonApi(); } diff --git a/src/Examples/NoEntityFrameworkExample/Startup.cs b/src/Examples/NoEntityFrameworkExample/Startup.cs index dfba27ddd9..b1f1d05188 100755 --- a/src/Examples/NoEntityFrameworkExample/Startup.cs +++ b/src/Examples/NoEntityFrameworkExample/Startup.cs @@ -1,4 +1,4 @@ -using JsonApiDotNetCore.Extensions; +using JsonApiDotNetCore.Extensions; using JsonApiDotNetCore.Services; using JsonApiDotNetCoreExample.Data; using JsonApiDotNetCoreExample.Models; @@ -55,7 +55,6 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AppDbContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); - loggerFactory.AddDebug(); context.Database.EnsureCreated(); diff --git a/src/Examples/OperationsExample/OperationsExample.csproj b/src/Examples/OperationsExample/OperationsExample.csproj index 69ad5653ce..02eeabe976 100644 --- a/src/Examples/OperationsExample/OperationsExample.csproj +++ b/src/Examples/OperationsExample/OperationsExample.csproj @@ -8,7 +8,7 @@ - + @@ -26,9 +26,4 @@ - - - - - diff --git a/src/Examples/OperationsExample/Startup.cs b/src/Examples/OperationsExample/Startup.cs index c11a3e9d26..a889ad85d6 100644 --- a/src/Examples/OperationsExample/Startup.cs +++ b/src/Examples/OperationsExample/Startup.cs @@ -27,7 +27,7 @@ public Startup(IHostingEnvironment env) public virtual IServiceProvider ConfigureServices(IServiceCollection services) { var loggerFactory = new LoggerFactory(); - loggerFactory.AddConsole(LogLevel.Trace); + loggerFactory.AddConsole(LogLevel.Warning); services.AddSingleton(loggerFactory); @@ -47,7 +47,6 @@ public virtual void Configure( context.Database.EnsureCreated(); loggerFactory.AddConsole(Config.GetSection("Logging")); - loggerFactory.AddDebug(); app.UseJsonApi(); } diff --git a/src/Examples/ReportsExample/appsettings.json b/src/Examples/ReportsExample/appsettings.json index 125f7a4ae9..5766595e6d 100644 --- a/src/Examples/ReportsExample/appsettings.json +++ b/src/Examples/ReportsExample/appsettings.json @@ -2,7 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Information" + "Default": "Warning" } } } diff --git a/src/JsonApiDotNetCore/Serialization/JsonApiSerializer.cs b/src/JsonApiDotNetCore/Serialization/JsonApiSerializer.cs index 20d119ff07..500101cc62 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonApiSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonApiSerializer.cs @@ -65,7 +65,11 @@ private string GetErrorJson(object responseObject, ILogger logger) } else { - logger?.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON."); + if (logger?.IsEnabled(LogLevel.Information) == true) + { + logger.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON."); + } + return JsonConvert.SerializeObject(responseObject); } } diff --git a/src/JsonApiDotNetCore/Services/EntityResourceService.cs b/src/JsonApiDotNetCore/Services/EntityResourceService.cs index 642ee00a57..a3094eb8f9 100644 --- a/src/JsonApiDotNetCore/Services/EntityResourceService.cs +++ b/src/JsonApiDotNetCore/Services/EntityResourceService.cs @@ -89,8 +89,10 @@ public virtual async Task GetRelationshipAsync(TId id, string relationsh if (relationshipName == null) throw new JsonApiException(422, "Relationship name not specified."); - - _logger.LogTrace($"Looking up '{relationshipName}'..."); + if (_logger.IsEnabled(LogLevel.Trace)) + { + _logger.LogTrace($"Looking up '{relationshipName}'..."); + } var entity = await _entities.GetAndIncludeAsync(id, relationshipName); // TODO: it would be better if we could distinguish whether or not the relationship was not found, @@ -166,7 +168,10 @@ protected virtual async Task> ApplyPageQueryAsync(IQueryable e if (!pageManager.IsPaginated) return await _entities.ToListAsync(entities); - _logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities"); + if (_logger?.IsEnabled(LogLevel.Information) == true) + { + _logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities"); + } return await _entities.PageAsync(entities, pageManager.PageSize, pageManager.CurrentPage); } diff --git a/src/JsonApiDotNetCore/Services/QueryAccessor.cs b/src/JsonApiDotNetCore/Services/QueryAccessor.cs index 41bc64151b..dc9ff7ef0a 100644 --- a/src/JsonApiDotNetCore/Services/QueryAccessor.cs +++ b/src/JsonApiDotNetCore/Services/QueryAccessor.cs @@ -45,7 +45,11 @@ public bool TryGetValue(string key, out T value) var stringValue = GetFilterValue(key); if (stringValue == null) { - _logger.LogInformation($"'{key}' was not found in the query collection"); + if (_logger.IsEnabled(LogLevel.Information)) + { + _logger.LogInformation($"'{key}' was not found in the query collection"); + } + return false; } @@ -56,7 +60,12 @@ public bool TryGetValue(string key, out T value) } catch (FormatException) { - _logger.LogInformation($"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}"); + if (_logger.IsEnabled(LogLevel.Information)) + { + _logger.LogInformation( + $"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}"); + } + return false; } } diff --git a/test/JsonApiDotNetCoreExampleTests/Helpers/Startups/MetaStartup.cs b/test/JsonApiDotNetCoreExampleTests/Helpers/Startups/MetaStartup.cs index df32a1223a..6bc5a08016 100644 --- a/test/JsonApiDotNetCoreExampleTests/Helpers/Startups/MetaStartup.cs +++ b/test/JsonApiDotNetCoreExampleTests/Helpers/Startups/MetaStartup.cs @@ -20,7 +20,7 @@ public MetaStartup(IHostingEnvironment env) public override IServiceProvider ConfigureServices(IServiceCollection services) { var loggerFactory = new LoggerFactory(); - loggerFactory.AddConsole(LogLevel.Trace); + loggerFactory.AddConsole(LogLevel.Warning); services .AddSingleton(loggerFactory) diff --git a/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj b/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj index b1df354bf7..53f1d4bf77 100755 --- a/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj +++ b/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj @@ -13,7 +13,7 @@ - + @@ -25,9 +25,8 @@ - + - diff --git a/test/JsonApiDotNetCoreExampleTests/appsettings.json b/test/JsonApiDotNetCoreExampleTests/appsettings.json index e65cee8d0d..c468439079 100644 --- a/test/JsonApiDotNetCoreExampleTests/appsettings.json +++ b/test/JsonApiDotNetCoreExampleTests/appsettings.json @@ -5,9 +5,9 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Error", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning", + "System": "Warning", + "Microsoft": "Warning" } } } diff --git a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj index f1d4044e0b..19b8cc61d2 100644 --- a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj +++ b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/NoEntityFrameworkTests/appsettings.json b/test/NoEntityFrameworkTests/appsettings.json index 01f85e6699..c468439079 100644 --- a/test/NoEntityFrameworkTests/appsettings.json +++ b/test/NoEntityFrameworkTests/appsettings.json @@ -5,9 +5,9 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning", + "System": "Warning", + "Microsoft": "Warning" } } } diff --git a/test/OperationsExampleTests/OperationsExampleTests.csproj b/test/OperationsExampleTests/OperationsExampleTests.csproj index 13f68faf5a..3b866d4207 100644 --- a/test/OperationsExampleTests/OperationsExampleTests.csproj +++ b/test/OperationsExampleTests/OperationsExampleTests.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj index a6ed346e7d..39132d0b0a 100644 --- a/test/UnitTests/UnitTests.csproj +++ b/test/UnitTests/UnitTests.csproj @@ -4,8 +4,8 @@ false - - + +