[Feature] Improve logging in providers
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- csharp
- Domaine
- authentication, tooling
Piste de recherche
Commencez par examiner le package CommunityToolkit.Diagnostics et les points d’entrée proposés ILogger, DebugLogger et LogManager. Inspectez ensuite WindowsProvider et MsalProvider, y compris l’intégration WithLogging de MsalProvider, et identifiez les blocs try/catch et les événements des providers mentionnés dans l’issue. Le travail est terminé lorsque la conception du logging est définie et que les deux providers exposent des informations utiles sur les erreurs et le troubleshooting.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the problem this feature would solve
When the authentication providers work, they are a delight. But when they don't work, they are rather difficult to troubleshoot.
Describe the solution
We need better logging to expose some insights into what the provider is doing, and what exceptions or failures are occurring. However, I feel like this is a great opportunity to handle logging in a more generic way across the whole toolkit.
I see a few moving parts:
ILoggerinterface - defines the basic functions of a logger. At a minimum, log a string message.DebugLoggerimplementation - extendsILoggerand usesSystem.Diagnostics.Debug.WriteLineto log messages. This is the default.LogManagersingleton - maintains activeILoggerimplementation used across the packages.
1. The logger interface and implementation
I'd like to see the ILogger interface put in the CommunityToolkit.Diagnostics package (link). This enables us to offer the simple DebugLogger based on System.Diagnostics.Debug.WriteLine
// Defines a basic logger
public interface ILogger
{
// Turn logging on or off
bool IsEnabled { get; set; }
// Log a string message, if enabled
void Log(string message);
}
// Default logger implementation
public class DebugLogger : ILogger
{
// Turned off by default.
public bool IsEnabled { get; set; } = false;
public void Log(string message)
{
if (IsEnabled)
{
System.Diagnostics.Debug.WriteLine(message);
}
}
}
// Manages the global logger instance
public class LogManager
{
public static LogManager Instance { get; } = new LogManager();
public ILogger Logger { get; set; } = new DebugLogger();
}
2. Consuming the logger
Developers with a custom logger can extend ILogger OR use a shim class instead to connect it to the LogManager:
// Set somewhere in app startup code
LogManager.Instance.Logger.IsEnabled = true;
// OR
// An example custom logger shim, if you don't want the default DebugLogger:
public class CustomLogger : ILogger
{
public bool IsEnabled { get; set; } = true;
public void Log(string message)
{
// Call your custom logger here
}
}
// Set somewhere in app startup code
LogManager.Instance.Logger = new CustomLogger();
3. Applying the logger to WindowsProvider
Pretty straight forward, ensure that every try/catch block sends any exceptions to the logger. Also look for opportunities to log other common events that could help with troubleshooting.
4. Applying the logger to MsalProvider
First ensure that every try/catch block sends any exceptions to the logger. But also, the MsalProvider leverages the PublicClientApplication object from MSAL for .NET which has a mechanism for passing in a method to handle the log output. This is enabled by using the WithLogging method on the client builder. This can be connected with the LogManager like so:
clientBuilder.WithLogging((level, message, containsPii) => LogManager.Instance.Logger.Log(message));
Additional context & Screenshots
Here is an example of a developers having issues with troubleshooting in the auth providers:
https://github.com/MicrosoftDocs/WindowsCommunityToolkitDocs/issues/593
Open questions
- Should the auth providers handle logging internally (local to the auth packages)?
- OR is a logging system the right thing to do?
- Where should the core classes to support logging go? In the Diagnostics or Common packages?
- Langage dominant
- C#
- Étoiles
- 156
- Forks
- 37
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de CommunityToolkit/Graph-Controls
-
bug :bug:
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
CommunityToolkit/Graph-Controls#211 · 3 commentaires ·
-
CommunityToolkit.Authentication.Msal use Microsoft Graph V4 but if you install V5,you cannot releaseOuvertebug :bug: needs attention :wave: needs triage :mag:
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
CommunityToolkit/Graph-Controls#208 · 20 commentaires ·
-
enhancement :sparkles:
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
-
Area: Providers
Difficulté 2/5 1-3 heures Accessibilité débutants 55/100
CommunityToolkit/Graph-Controls#195 · 1 commentaire ·
-
Area: Providers bug :bug:
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
CommunityToolkit/Graph-Controls#189 · 3 commentaires ·
Toutes les issues de CommunityToolkit/Graph-Controls
Issues similaires
-
[Core] IPlatformServices.PrefersDarkTheme: the desktop's theme as the signed-in user sees itOuvertearea: core bug help wanted ready
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
ZaidX88/sluice#265 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
area: remote bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
Install a C# EnvironmentOuverte📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
CodeYourFuture/Module-Tools#712 ·
-
A: Mapping P3: Standard T: New Feature
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
space-wizards/space-station-14#46878 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 Une demi-journée Accessibilité débutants 60/100
CommunityToolkit/Windows#896 · 2 commentaires ·