forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Logging policy prototype w/ ILogger #6
Draft
m-redding
wants to merge
2
commits into
logging-policy-prototype
Choose a base branch
from
logging-policy-ilogger
base: logging-policy-prototype
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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
78 changes: 78 additions & 0 deletions
78
sdk/core/System.ClientModel/src/Internal/ClientModelLogMessages.cs
This file contains 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,78 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace System.ClientModel.Internal; | ||
|
||
internal static partial class ClientModelLogMessages | ||
{ | ||
private const int RequestEvent = 1; | ||
private const int RequestContentEvent = 2; | ||
private const int ResponseEvent = 5; | ||
private const int ResponseContentEvent = 6; | ||
private const int ResponseDelayEvent = 7; | ||
private const int ErrorResponseEvent = 8; | ||
private const int ErrorResponseContentEvent = 9; | ||
private const int RequestRetryingEvent = 10; | ||
private const int ResponseContentBlockEvent = 11; | ||
private const int ErrorResponseContentBlockEvent = 12; | ||
private const int ResponseContentTextEvent = 13; | ||
private const int ErrorResponseContentTextEvent = 14; | ||
private const int ResponseContentTextBlockEvent = 15; | ||
private const int ErrorResponseContentTextBlockEvent = 16; | ||
private const int RequestContentTextEvent = 17; | ||
private const int ExceptionResponseEvent = 18; | ||
private const int PipelineTransportOptionsNotAppliedEvent = 23; // TODO | ||
|
||
[LoggerMessage(RequestEvent, LogLevel.Information, "Request [{requestId}] {method} {uri}\r\n{headers}client assembly: {assemblyName}", EventName = "Request")] | ||
public static partial void Request(ILogger logger, string requestId, string method, string uri, string headers, string? assemblyName); | ||
|
||
// TODO - these are verbose logs in EventSource, should they be trace logs here? | ||
[LoggerMessage(RequestContentEvent, LogLevel.Information, "Request [{requestId}] content: {content}", EventName = "RequestContent")] | ||
public static partial void RequestContent(ILogger logger, string requestId, byte[] content); | ||
|
||
// same as above | ||
[LoggerMessage(RequestContentTextEvent, LogLevel.Information, "Request [{requestId}] content: {content}", EventName="RequestContentText")] | ||
public static partial void RequestContentText(ILogger logger, string requestID, string content); | ||
|
||
[LoggerMessage(ResponseEvent, LogLevel.Information, "Response [{requestId}] {status} {reasonPhrase} ({seconds:00.0}s)\r\n{headers}", EventName = "Response")] | ||
public static partial void Response(ILogger logger, string requestID, int status, string reasonPhrase, double seconds, string headers); | ||
|
||
// same | ||
[LoggerMessage(ResponseContentEvent, LogLevel.Information, "Response [{requestId}] content: {content}", EventName = "ResponseContent")] | ||
public static partial void ResponseContent(ILogger logger, string requestId, byte[] content); | ||
|
||
[LoggerMessage(ResponseContentTextEvent, LogLevel.Information, "Response [{requestId}] content: {content}", EventName = "ResponseContentText")] | ||
public static partial void ResponseContentText(ILogger logger, string requestId, string content); | ||
|
||
[LoggerMessage(ResponseContentBlockEvent, LogLevel.Information, "Response [{requestId}] content block {blockNumber}: {content}", EventName = "ResponseContentBlock")] | ||
public static partial void ResponseContentBlock(ILogger logger, string requestId, int blockNumber, byte[] content); | ||
|
||
[LoggerMessage(ResponseContentTextBlockEvent, LogLevel.Information, "Response [{requestId}] content block {blockNumber}: {content}", EventName = "ResponseContentTextBlock")] | ||
public static partial void ResponseContentTextBlock(ILogger logger, string requestId, int blockNumber, string content); | ||
|
||
[LoggerMessage(ErrorResponseEvent, LogLevel.Warning, "Error response [{requestId}] {status} {reasonPhrase} ({seconds:00.0}s)\r\n{headers}", EventName = "ErrorResponse")] | ||
public static partial void ErrorResponse(ILogger logger, string requestId, int status, string reasonPhrase, double seconds, string headers); | ||
|
||
[LoggerMessage(ErrorResponseContentEvent, LogLevel.Warning, "Error response [{requestId}] content: {content}", EventName = "ErrorResponseContent")] | ||
public static partial void ErrorResponseContent(ILogger logger, string requestId, byte[] content); | ||
|
||
[LoggerMessage(ErrorResponseContentTextEvent, LogLevel.Warning, "Error response [{requestId}] content: {content}", EventName = "ErrorResponseContentText")] | ||
public static partial void ErrorResponseContentText(ILogger logger, string requestId, string content); | ||
|
||
[LoggerMessage(ErrorResponseContentBlockEvent, LogLevel.Warning, "Error response [{requestId}] content block {blockNumber}: {content}", EventName = "ErrorResponseContentBlock")] | ||
public static partial void ErrorResponseContentBlock(ILogger logger, string requestId, int blockNumber, byte[] content); | ||
|
||
[LoggerMessage(ErrorResponseContentTextBlockEvent, LogLevel.Warning, "Error response [{requestId}] content block {blockNumber}: {content}", EventName = "ErrorResponseContentTextBlock")] | ||
public static partial void ErrorResponseContentTextBlock(ILogger logger, string requestId, int blockNumber, string content); | ||
|
||
[LoggerMessage(RequestRetryingEvent, LogLevel.Information, "Request [{requestId}] attempt number {retryCount} took {seconds:00.0}s", EventName = "RequestRetrying")] | ||
public static partial void RequestRetrying(ILogger logger, string requestId, int retryCount, double seconds); | ||
|
||
[LoggerMessage(ExceptionResponseEvent, LogLevel.Information, "Request [{requestId}] exception {exception}", EventName = "ExceptionResponse")] | ||
public static partial void ExceptionResponse(ILogger logger, string requestId, string exception); | ||
} |
This file contains 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
Oops, something went wrong.
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.
Opted to do ILoggerFactory over ILogger b/c:
https://learn.microsoft.com/en-us/dotnet/core/extensions/logging-library-authors#when-to-use-the-iloggerfactory-interface