[Feature] Improve logging in providers
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- csharp
- Área
- authentication, tooling
Línea de trabajo
Comienza revisando el paquete CommunityToolkit.Diagnostics y los puntos de entrada propuestos ILogger, DebugLogger y LogManager. Después inspecciona WindowsProvider y MsalProvider, incluida la integración de WithLogging de MsalProvider, e identifica los bloques try/catch y los eventos de los proveedores mencionados en el issue. Se considera terminado cuando el diseño de logging esté definido y ambos proveedores expongan información útil sobre errores y troubleshooting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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?
- Lenguaje dominante
- C#
- Estrellas
- 156
- Forks
- 37
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/Graph-Controls
-
bug :bug:
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
CommunityToolkit/Graph-Controls#211 · 3 comentarios ·
-
CommunityToolkit.Authentication.Msal use Microsoft Graph V4 but if you install V5,you cannot releaseAbiertobug :bug: needs attention :wave: needs triage :mag:
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
CommunityToolkit/Graph-Controls#208 · 20 comentarios ·
-
enhancement :sparkles:
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
-
Area: Providers
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
CommunityToolkit/Graph-Controls#195 · 1 comentario ·
-
Area: Providers bug :bug:
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
CommunityToolkit/Graph-Controls#189 · 3 comentarios ·
Todos los issues de CommunityToolkit/Graph-Controls
Issues similares
-
[Core] IPlatformServices.PrefersDarkTheme: the desktop's theme as the signed-in user sees itAbiertoarea: core bug help wanted ready
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
ZaidX88/sluice#265 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area: remote bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Install a C# EnvironmentAbierto📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
CodeYourFuture/Module-Tools#712 ·
-
A: Mapping P3: Standard T: New Feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
space-wizards/space-station-14#46878 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 60/100
CommunityToolkit/Windows#896 · 2 comentarios ·