-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Westinm/downstreamapi-logging (#2206)
- Loading branch information
Showing
5 changed files
with
100 additions
and
6 deletions.
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
57 changes: 57 additions & 0 deletions
57
src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.Logger.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,57 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
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"); | ||
|
||
|
||
/// <summary> | ||
/// Logger for handling options exceptions in DownstreamApi. | ||
/// </summary> | ||
/// <param name="logger">ILogger.</param> | ||
/// <param name="ServiceName">Name of API receiving request.</param> | ||
/// <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 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
16 changes: 16 additions & 0 deletions
16
src/Microsoft.Identity.Web.DownstreamApi/DownstreamApiLoggingEventId.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,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(100, "HttpRequestError"); | ||
public static readonly EventId UnauthenticatedApiCall = new(101, "UnauthenticatedApiCall"); | ||
#pragma warning restore IDE1006 // Naming styles | ||
} | ||
} |