You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory/develop/msal-logging-dotnet.md
+90-24Lines changed: 90 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,38 +23,104 @@ ms.custom: aaddev
23
23
24
24
In MSAL, logging is set at application creation using the `.WithLogging` builder modifier. This method takes optional parameters:
25
25
26
+
-`IIdentityLogger` is the logging implementation used by MSAL.NET to produce logs for debugging or health check purposes. Logs are only sent if logging is enabled.
26
27
-`Level` enables you to decide which level of logging you want. Setting it to Errors will only get errors
27
-
-`PiiLoggingEnabled` enables you to log personal and organizational data (PII) if set to true. By default, this is set to false, so that your application doesn't log personal data.
28
+
-`PiiLoggingEnabled` enables you to log personal and organizational data (PII) if set to true. By default, this parameter is set to false, so that your application doesn't log personal data.
28
29
-`LogCallback` is set to a delegate that does the logging. If `PiiLoggingEnabled` is true, this method will receive messages that can have PII, in which case the `containsPii` flag will be set to true.
29
30
-`DefaultLoggingEnabled` enables the default logging for the platform. By default it's false. If you set it to true it uses Event Tracing in Desktop/UWP applications, NSLog on iOS and logcat on Android.
// Checks to see if logging is enabled at given eventLogLevel.
41
+
//
42
+
// Parameters:
43
+
// eventLogLevel:
44
+
// Log level of a message.
45
+
boolIsEnabled(EventLogLeveleventLogLevel);
46
+
47
+
//
48
+
// Summary:
49
+
// Writes a log entry.
50
+
//
51
+
// Parameters:
52
+
// entry:
53
+
// Defines a structured message to be logged at the provided Microsoft.IdentityModel.Abstractions.LogEntry.EventLogLevel.
54
+
voidLog(LogEntryentry);
55
+
}
55
56
}
56
57
```
57
58
59
+
> [!NOTE]
60
+
> Partner libraries (`Microsoft.Identity.Web`, `Microsoft.IdentityModel`) provide implementations of this interface already for various environments (in particular ASP.NET Core)
61
+
62
+
### IIdentityLogger Implementation
63
+
64
+
The following code snippets are examples of such an implementation. If you use the .NET core configuration, environment variable driven logs levels can be provided for free, in addition to the configuration file based log levels.
65
+
66
+
#### Log level from configuration file
67
+
68
+
It's highly recommended to configure your code to use a configuration file in your environment to set the log level as it will enable your code to change the MSAL logging level without needing to rebuild or restart the application. This is critical for diagnostic purposes, enabling us to quickly gather the required logs from the application that is currently deployed and in production. Verbose logging can be costly so it's best to use the *Information* level by default and enable verbose logging when an issue is encountered. [See JSON configuration provider](https://docs.microsoft.com/aspnet/core/fundamentals/configuration#json-configuration-provider) for an example on how to load data from a configuration file without restarting the application.
69
+
70
+
#### Log Level as Environment Variable
71
+
72
+
Another option we recommended is to configure your code to use an environment variable on the machine to set the log level as it will enable your code to change the MSAL logging level without needing to rebuild the application. This is critical for diagnostic purposes, enabling us to quickly gather the required logs from the application that is currently deployed and in production.
73
+
74
+
See [EventLogLevel](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/dev/src/Microsoft.IdentityModel.Abstractions/EventLogLevel.cs) for details on the available log levels.
75
+
76
+
Example:
77
+
78
+
```CSharp
79
+
classMyIdentityLogger : IIdentityLogger
80
+
{
81
+
publicEventLogLevelMinLogLevel { get; }
82
+
83
+
publicTestIdentityLogger()
84
+
{
85
+
//Try to pull the log level from an environment variable
Copy file name to clipboardExpand all lines: includes/active-directory-develop-error-logging-introduction.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,19 +8,24 @@ ms.topic: include
8
8
# Purpose:
9
9
# Ingested by Microsoft identity platform articles in /articles/active-directory/develop/* that document error logging for the different platforms.
10
10
---
11
-
The Microsoft Authentication Library (MSAL) apps generate log messages that can help diagnose issues. An app can configure logging with a few lines of code, and have custom control over the level of detail and whether or not personal and organizational data is logged. We recommend you create an MSAL logging callback and provide a way for users to submit logs when they have authentication issues.
11
+
The Microsoft Authentication Library (MSAL) apps generate log messages that can help diagnose issues. An app can configure logging with a few lines of code, and have custom control over the level of detail and whether or not personal and organizational data is logged. We recommend you create an MSAL logging implementation and provide a way for users to submit logs when they have authentication issues.
12
12
13
13
## Logging levels
14
14
15
15
MSAL provides several levels of logging detail:
16
16
17
+
- LogAlways: No level filtering is done on this log level. Log messages of all levels will be logged.
18
+
- Critical: Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.
17
19
- Error: Indicates something has gone wrong and an error was generated. Used for debugging and identifying problems.
18
20
- Warning: There hasn't necessarily been an error or failure, but are intended for diagnostics and pinpointing problems.
19
-
- Info: MSAL will log events intended for informational purposes not necessarily intended for debugging.
20
-
- Verbose: Default. MSAL logs the full details of library behavior.
21
+
- Informational: MSAL will log events intended for informational purposes not necessarily intended for debugging.
22
+
- Verbose (Default): MSAL logs the full details of library behavior.
23
+
24
+
> [!NOTE]
25
+
> Not all log levels are available for all MSAL SDK's
21
26
22
27
## Personal and organizational data
23
28
24
29
By default, the MSAL logger doesn't capture any highly sensitive personal or organizational data. The library provides the option to enable logging personal and organizational data if you decide to do so.
25
30
26
-
The following sections provide more details about MSAL error logging for your application.
31
+
The following sections provide more details about MSAL error logging for your application.
0 commit comments