-
Notifications
You must be signed in to change notification settings - Fork 245
Westinm/downstreamapi-logging #2206
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f0885a0
refactor the sample to use IDownstreamApi
westin-m b2d1833
create logger instance
westin-m 75c7797
Initial creation of logger class
westin-m 71a6cf1
Merge branch 'main' into westinm/downstreamapi-logging
westin-m 297c9ae
Merge branch 'main' into westinm/downstreamapi-logging
westin-m e5ff77d
Create EventId class
westin-m 9658c25
Rework error to include servicename
westin-m bdb5225
remove unused usings
westin-m d0676a0
Merge branch 'main' into westinm/downstreamapi-logging
westin-m 9fea6bc
PR edits
westin-m 398074c
PR edit
westin-m 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
58 changes: 58 additions & 0 deletions
58
src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.Logger.cs
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,58 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
westin-m marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.Identity.Web | ||
| { | ||
| /// <summary> | ||
| /// LoggerMessage class for DownstreamApi | ||
| /// </summary> | ||
| internal partial class DownstreamApi | ||
| { | ||
| internal static class Logger | ||
| { | ||
| private static readonly Action<ILogger, string, string, string, Exception?> s_httpRequestError = | ||
| LoggerMessage.Define<string, string, string>( | ||
| LogLevel.Debug, | ||
| DownstreamApiLoggingEventId.HttpRequestError, | ||
| "[MsIdWeb] An error occurred during HTTP Request. " + | ||
| "ServiceName: {serviceName}, " + | ||
| "BaseUrl: {BaseUrl}, " + | ||
| "RelativePath: {RelativePath} "); | ||
|
|
||
| private static readonly Action<ILogger, Exception?> s_unauthenticatedApiCall = | ||
| LoggerMessage.Define( | ||
| LogLevel.Information, | ||
| DownstreamApiLoggingEventId.UnauthenticatedApiCall, | ||
| "[MsIdWeb] An unauthenticated call was made to the Api with null Scopes"); | ||
westin-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| /// <summary> | ||
| /// Logger for handling options exceptions in DownstreamApi | ||
westin-m marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// </summary> | ||
| /// <param name="logger">ILogger</param> | ||
| /// <param name="ServiceName">Name of Api receiving request</param> | ||
westin-m marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// <param name="BaseUrl">Base url from appsettings.</param> | ||
| /// <param name="RelativePath">Relative path from appsettings.</param> | ||
| /// <param name="ex">Exception</param> | ||
| public static void HttpRequestError( | ||
| ILogger logger, | ||
| string ServiceName, | ||
| string BaseUrl, | ||
| string RelativePath, | ||
| Exception? ex) => s_httpRequestError(logger, ServiceName, BaseUrl, RelativePath, ex); | ||
|
|
||
| /// <summary> | ||
| /// Logger for unauthenticated internal Api call in DownstreamApi | ||
| /// </summary> | ||
| /// <param name="logger">Logger</param> | ||
| /// <param name="ex">Exception</param> | ||
| public static void UnauthenticatedApiCall( | ||
| ILogger logger, | ||
| Exception? ex) => s_unauthenticatedApiCall(logger, ex); | ||
| } | ||
| } | ||
| } | ||
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
16 changes: 16 additions & 0 deletions
16
src/Microsoft.Identity.Web.DownstreamApi/DownstreamApiLoggingEventId.cs
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,16 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.Identity.Web | ||
| { | ||
| internal static class DownstreamApiLoggingEventId | ||
| { | ||
| #pragma warning disable IDE1006 // Naming styles | ||
| // DownstreamApi EventIds 100+ | ||
| public static readonly EventId HttpRequestError = new EventId(100, "HttpRequestError"); | ||
| public static readonly EventId UnauthenticatedApiCall = new EventId(101, "UnauthenticatedApiCall"); | ||
westin-m marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #pragma warning restore IDE1006 // Naming styles | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.