This repository was archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Improve logging and add more messages #76
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// 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.AspNet.StaticFiles | ||
{ | ||
/// <summary> | ||
/// Defines *all* the logger messages produced by static files | ||
/// </summary> | ||
internal static class LoggerExtensions | ||
{ | ||
private static Action<ILogger, string, Exception> _logMethodNotSupported; | ||
private static Action<ILogger, string, string, Exception> _logFileServed; | ||
private static Action<ILogger, string, Exception> _logPathMismatch; | ||
private static Action<ILogger, string, Exception> _logFileTypeNotSupported; | ||
private static Action<ILogger, string, Exception> _logFileNotFound; | ||
private static Action<ILogger, string, Exception> _logPathNotModified; | ||
private static Action<ILogger, string, Exception> _logPreconditionFailed; | ||
private static Action<ILogger, int, string, Exception> _logHandled; | ||
private static Action<ILogger, string, Exception> _logRangeNotSatisfiable; | ||
private static Action<ILogger, StringValues, string, Exception> _logSendingFileRange; | ||
private static Action<ILogger, StringValues, string, Exception> _logCopyingFileRange; | ||
private static Action<ILogger, long, string, string, Exception> _logCopyingBytesToResponse; | ||
private static Action<ILogger, string, Exception> _logMultipleFileRanges; | ||
|
||
static LoggerExtensions() | ||
{ | ||
_logMethodNotSupported = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Verbose, | ||
eventId: 1, | ||
formatString: "{Method} requests are not supported"); | ||
_logFileServed = LoggerMessage.Define<string, string>( | ||
logLevel: LogLevel.Information, | ||
eventId: 2, | ||
formatString: "Sending file. Request path: '{VirtualPath}'. Physical path: '{PhysicalPath}'"); | ||
_logPathMismatch = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Verbose, | ||
eventId: 3, | ||
formatString: "The request path {Path} does not match the path filter"); | ||
_logFileTypeNotSupported = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Verbose, | ||
eventId: 4, | ||
formatString: "The request path {Path} does not match a supported file type"); | ||
_logFileNotFound = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Verbose, | ||
eventId: 5, | ||
formatString: "The request path {Path} does not match an existing file"); | ||
_logPathNotModified = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Information, | ||
eventId: 6, | ||
formatString: "The file {Path} was not modified"); | ||
_logPreconditionFailed = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Information, | ||
eventId: 7, | ||
formatString: "Precondition for {Path} failed"); | ||
_logHandled = LoggerMessage.Define<int, string>( | ||
logLevel: LogLevel.Verbose, | ||
eventId: 8, | ||
formatString: "Handled. Status code: {StatusCode} File: {Path}"); | ||
_logRangeNotSatisfiable = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Warning, | ||
eventId: 9, | ||
formatString: "Range not satisfiable for {Path}"); | ||
_logSendingFileRange = LoggerMessage.Define<StringValues, string>( | ||
logLevel: LogLevel.Information, | ||
eventId: 10, | ||
formatString: "Sending {Range} of file {Path}"); | ||
_logCopyingFileRange = LoggerMessage.Define<StringValues, string>( | ||
logLevel: LogLevel.Verbose, | ||
eventId: 11, | ||
formatString: "Copying {Range} of file {Path} to the response body"); | ||
_logCopyingBytesToResponse = LoggerMessage.Define<long, string, string>( | ||
logLevel: LogLevel.Verbose, | ||
eventId: 12, | ||
formatString: "Copying bytes {Start}-{End} of file {Path} to response body"); | ||
_logMultipleFileRanges = LoggerMessage.Define<string>( | ||
logLevel: LogLevel.Warning, | ||
eventId: 13, | ||
formatString: "Multiple ranges are not allowed: '{Ranges}'"); | ||
} | ||
|
||
public static void LogRequestMethodNotSupported(this ILogger logger, string method) | ||
{ | ||
_logMethodNotSupported(logger, method, null); | ||
} | ||
|
||
public static void LogFileServed(this ILogger logger, string virtualPath, string physicalPath) | ||
{ | ||
if (string.IsNullOrEmpty(physicalPath)) | ||
{ | ||
physicalPath = "N/A"; | ||
} | ||
_logFileServed(logger, virtualPath, physicalPath, null); | ||
} | ||
|
||
public static void LogPathMismatch(this ILogger logger, string path) | ||
{ | ||
_logPathMismatch(logger, path, null); | ||
} | ||
|
||
public static void LogFileTypeNotSupported(this ILogger logger, string path) | ||
{ | ||
_logFileTypeNotSupported(logger, path, null); | ||
} | ||
|
||
public static void LogFileNotFound(this ILogger logger, string path) | ||
{ | ||
_logFileNotFound(logger, path, null); | ||
} | ||
|
||
public static void LogPathNotModified(this ILogger logger, string path) | ||
{ | ||
_logPathNotModified(logger, path, null); | ||
} | ||
|
||
public static void LogPreconditionFailed(this ILogger logger, string path) | ||
{ | ||
_logPreconditionFailed(logger, path, null); | ||
} | ||
|
||
public static void LogHandled(this ILogger logger, int statusCode, string path) | ||
{ | ||
_logHandled(logger, statusCode, path, null); | ||
} | ||
|
||
public static void LogRangeNotSatisfiable(this ILogger logger, string path) | ||
{ | ||
_logRangeNotSatisfiable(logger, path, null); | ||
} | ||
|
||
public static void LogSendingFileRange(this ILogger logger, StringValues range, string path) | ||
{ | ||
_logSendingFileRange(logger, range, path, null); | ||
} | ||
|
||
public static void LogCopyingFileRange(this ILogger logger, StringValues range, string path) | ||
{ | ||
_logCopyingFileRange(logger, range, path, null); | ||
} | ||
|
||
public static void LogCopyingBytesToResponse(this ILogger logger, long start, long? end, string path) | ||
{ | ||
_logCopyingBytesToResponse( | ||
logger, | ||
start, | ||
end != null ? end.ToString() : "*", | ||
path, | ||
null); | ||
} | ||
|
||
public static void LogMultipleFileRanges(this ILogger logger, string range) | ||
{ | ||
_logMultipleFileRanges(logger, range, null); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This is more of an implementation detail