Repository navigation
Expand file tree
/
Copy pathLoggerExtensions.cs
More file actions
154 lines (138 loc) · 6.74 KB
/
Copy pathLoggerExtensions.cs
File metadata and controls
154 lines (138 loc) · 6.74 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.StaticFiles
{
/// <summary>
/// Defines *all* the logger messages produced by static files
/// </summary>
internal static class LoggerExtensions
{
private static Action<ILogger, string, Exception> _methodNotSupported;
private static Action<ILogger, string, string, Exception> _fileServed;
private static Action<ILogger, string, Exception> _pathMismatch;
private static Action<ILogger, string, Exception> _fileTypeNotSupported;
private static Action<ILogger, string, Exception> _fileNotFound;
private static Action<ILogger, string, Exception> _fileNotModified;
private static Action<ILogger, string, Exception> _preconditionFailed;
private static Action<ILogger, int, string, Exception> _handled;
private static Action<ILogger, string, Exception> _rangeNotSatisfiable;
private static Action<ILogger, StringValues, string, Exception> _sendingFileRange;
private static Action<ILogger, StringValues, string, Exception> _copyingFileRange;
private static Action<ILogger, Exception> _writeCancelled;
private static Action<ILogger, Exception> _endpointMatched;
static LoggerExtensions()
{
_methodNotSupported = LoggerMessage.Define<string>(
logLevel: LogLevel.Debug,
eventId: new EventId(1, "MethodNotSupported"),
formatString: "{Method} requests are not supported");
_fileServed = LoggerMessage.Define<string, string>(
logLevel: LogLevel.Information,
eventId: new EventId(2, "FileServed"),
formatString: "Sending file. Request path: '{VirtualPath}'. Physical path: '{PhysicalPath}'");
_pathMismatch = LoggerMessage.Define<string>(
logLevel: LogLevel.Debug,
eventId: new EventId(3, "PathMismatch"),
formatString: "The request path {Path} does not match the path filter");
_fileTypeNotSupported = LoggerMessage.Define<string>(
logLevel: LogLevel.Debug,
eventId: new EventId(4, "FileTypeNotSupported"),
formatString: "The request path {Path} does not match a supported file type");
_fileNotFound = LoggerMessage.Define<string>(
logLevel: LogLevel.Debug,
eventId: new EventId(5, "FileNotFound"),
formatString: "The request path {Path} does not match an existing file");
_fileNotModified = LoggerMessage.Define<string>(
logLevel: LogLevel.Information,
eventId: new EventId(6, "FileNotModified"),
formatString: "The file {Path} was not modified");
_preconditionFailed = LoggerMessage.Define<string>(
logLevel: LogLevel.Information,
eventId: new EventId(7, "PreconditionFailed"),
formatString: "Precondition for {Path} failed");
_handled = LoggerMessage.Define<int, string>(
logLevel: LogLevel.Debug,
eventId: new EventId(8, "Handled"),
formatString: "Handled. Status code: {StatusCode} File: {Path}");
_rangeNotSatisfiable = LoggerMessage.Define<string>(
logLevel: LogLevel.Warning,
eventId: new EventId(9, "RangeNotSatisfiable"),
formatString: "Range not satisfiable for {Path}");
_sendingFileRange = LoggerMessage.Define<StringValues, string>(
logLevel: LogLevel.Information,
eventId: new EventId(10, "SendingFileRange"),
formatString: "Sending {Range} of file {Path}");
_copyingFileRange = LoggerMessage.Define<StringValues, string>(
logLevel: LogLevel.Debug,
eventId: new EventId(11, "CopyingFileRange"),
formatString: "Copying {Range} of file {Path} to the response body");
_writeCancelled = LoggerMessage.Define(
logLevel: LogLevel.Debug,
eventId: new EventId(14, "WriteCancelled"),
formatString: "The file transmission was cancelled");
_endpointMatched = LoggerMessage.Define(
logLevel: LogLevel.Debug,
eventId: new EventId(15, "EndpointMatched"),
formatString: "Static files was skipped as the request already matched an endpoint.");
}
public static void RequestMethodNotSupported(this ILogger logger, string method)
{
_methodNotSupported(logger, method, null);
}
public static void FileServed(this ILogger logger, string virtualPath, string physicalPath)
{
if (string.IsNullOrEmpty(physicalPath))
{
physicalPath = "N/A";
}
_fileServed(logger, virtualPath, physicalPath, null);
}
public static void EndpointMatched(this ILogger logger)
{
_endpointMatched(logger, null);
}
public static void PathMismatch(this ILogger logger, string path)
{
_pathMismatch(logger, path, null);
}
public static void FileTypeNotSupported(this ILogger logger, string path)
{
_fileTypeNotSupported(logger, path, null);
}
public static void FileNotFound(this ILogger logger, string path)
{
_fileNotFound(logger, path, null);
}
public static void FileNotModified(this ILogger logger, string path)
{
_fileNotModified(logger, path, null);
}
public static void PreconditionFailed(this ILogger logger, string path)
{
_preconditionFailed(logger, path, null);
}
public static void Handled(this ILogger logger, int statusCode, string path)
{
_handled(logger, statusCode, path, null);
}
public static void RangeNotSatisfiable(this ILogger logger, string path)
{
_rangeNotSatisfiable(logger, path, null);
}
public static void SendingFileRange(this ILogger logger, StringValues range, string path)
{
_sendingFileRange(logger, range, path, null);
}
public static void CopyingFileRange(this ILogger logger, StringValues range, string path)
{
_copyingFileRange(logger, range, path, null);
}
public static void WriteCancelled(this ILogger logger, Exception ex)
{
_writeCancelled(logger, ex);
}
}
}