Skip to content

Commit

Permalink
Merge pull request #367 from sungam3r/cleanup
Browse files Browse the repository at this point in the history
Remove excessive dependencies + format
  • Loading branch information
nblumhardt authored Mar 25, 2024
2 parents 0b2a9ab + 656b79e commit c862bfc
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion samples/Sample/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public IActionResult Privacy()
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
2 changes: 1 addition & 1 deletion samples/Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.AspNetCore\Serilog.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RequestLoggingMiddleware
readonly Func<HttpContext, string, double, int, IEnumerable<LogEventProperty>> _getMessageTemplateProperties;
readonly ILogger? _logger;
readonly bool _includeQueryInRequestPath;
static readonly LogEventProperty[] NoProperties = Array.Empty<LogEventProperty>();
static readonly LogEventProperty[] NoProperties = [];

public RequestLoggingMiddleware(RequestDelegate next, DiagnosticContext diagnosticContext, RequestLoggingOptions options)
{
Expand Down Expand Up @@ -102,7 +102,7 @@ bool LogCompletion(HttpContext httpContext, DiagnosticContextCollector collector
properties,
traceId,
spanId);

logger.Write(evt);

return false;
Expand Down
5 changes: 2 additions & 3 deletions src/Serilog.AspNetCore/AspNetCore/RequestLoggingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ static LogEventLevel DefaultGetLevel(HttpContext ctx, double _, Exception? ex) =
: LogEventLevel.Information;

static IEnumerable<LogEventProperty> DefaultGetMessageTemplateProperties(HttpContext httpContext, string requestPath, double elapsedMs, int statusCode) =>
new[]
{
[
new LogEventProperty("RequestMethod", new ScalarValue(httpContext.Request.Method)),
new LogEventProperty("RequestPath", new ScalarValue(requestPath)),
new LogEventProperty("StatusCode", new ScalarValue(statusCode)),
new LogEventProperty("Elapsed", new ScalarValue(elapsedMs))
};
];

/// <summary>
/// Gets or sets the message template. The default value is
Expand Down
3 changes: 0 additions & 3 deletions src/Serilog.AspNetCore/Serilog.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
<!-- The versions of all references in this group must match the major and minor components of the package version prefix. -->
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<!-- Temporary addition to pull in trace/span support -->
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net462' and '$(TargetFramework)' != 'netstandard2.0' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ public async Task RequestLoggingMiddlewareShouldEnrichWithCustomisedProperties()
{
options.MessageTemplate = "HTTP {RequestMethod} responded {Status} in {ElapsedMilliseconds:0.0000} ms";
options.GetMessageTemplateProperties = (ctx, _, elapsedMs, status) =>
new[]
{
[
new LogEventProperty("RequestMethod", new ScalarValue(ctx.Request.Method)),
new LogEventProperty("Status", new ScalarValue(status)),
new LogEventProperty("ElapsedMilliseconds", new ScalarValue(elapsedMs))
};
];
});

await web.CreateClient().GetAsync("/resource");
Expand Down Expand Up @@ -164,7 +163,7 @@ WebApplicationFactory<TestStartup> Setup(

return web;
}

[Fact]
public async Task RequestLoggingMiddlewareShouldAddTraceAndSpanIds()
{
Expand Down
2 changes: 1 addition & 1 deletion test/Serilog.AspNetCore.Tests/Support/SerilogSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Serilog.AspNetCore.Tests.Support;

public class SerilogSink : ILogEventSink
{
public List<LogEvent> Writes { get; set; } = new();
public List<LogEvent> Writes { get; set; } = [];

public void Emit(LogEvent logEvent)
{
Expand Down

0 comments on commit c862bfc

Please sign in to comment.