forked from dotnet/aspnetcore
/
HttpLoggingExtensions.cs
40 lines (31 loc) · 1.95 KB
/
HttpLoggingExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.HttpLogging;
internal static partial class HttpLoggingExtensions
{
public static void RequestLog(this ILogger logger, HttpRequestLog requestLog) => logger.Log(
LogLevel.Information,
new EventId(1, "RequestLog"),
requestLog,
exception: null,
formatter: HttpRequestLog.Callback);
public static void ResponseLog(this ILogger logger, HttpResponseLog responseLog) => logger.Log(
LogLevel.Information,
new EventId(2, "ResponseLog"),
responseLog,
exception: null,
formatter: HttpResponseLog.Callback);
[LoggerMessage(3, LogLevel.Information, "RequestBody: {Body}{status}", EventName = "RequestBody")]
public static partial void RequestBody(this ILogger logger, string body, string status);
[LoggerMessage(4, LogLevel.Information, "ResponseBody: {Body}", EventName = "ResponseBody")]
public static partial void ResponseBody(this ILogger logger, string body);
[LoggerMessage(5, LogLevel.Debug, "Decode failure while converting body.", EventName = "DecodeFailure")]
public static partial void DecodeFailure(this ILogger logger, Exception ex);
[LoggerMessage(6, LogLevel.Debug, "Unrecognized Content-Type for {Name} body.", EventName = "UnrecognizedMediaType")]
public static partial void UnrecognizedMediaType(this ILogger logger, string name);
[LoggerMessage(7, LogLevel.Debug, "No Content-Type header for {Name} body.", EventName = "NoMediaType")]
public static partial void NoMediaType(this ILogger logger, string name);
[LoggerMessage(8, LogLevel.Information, "Response Duration: {Duration}ms, Body: {Body}", EventName = "ResponseDurationAndBody")]
public static partial void ResponseBodyWithDuration(this ILogger logger, string body, double duration);
}