[Feature] Improve logging in providers
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- csharp
调研方向
首先检查 CommunityToolkit.Diagnostics 包以及拟议的 ILogger、DebugLogger 和 LogManager 入口点。然后检查 WindowsProvider 和 MsalProvider,包括 MsalProvider 的 WithLogging 集成,并找出 issue 中提到的 try/catch 块和 provider 事件。完成的标准是 logging 设计已经确定,并且两个 provider 都能提供有用的失败信息和故障排查信息。
由索引模型根据 Issue 内容生成。
描述
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?
- 主要语言
- C#
- 星标
- 156
- 派生
- 37
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CommunityToolkit/Graph-Controls 的其他 Issue
-
bug :bug:
难度 4/5 3-5 天 新手友好度 25/100
CommunityToolkit/Graph-Controls#211 · 3 条评论 ·
-
CommunityToolkit.Authentication.Msal use Microsoft Graph V4 but if you install V5,you cannot release未关闭bug :bug: needs attention :wave: needs triage :mag:
难度 4/5 3-5 天 新手友好度 25/100
CommunityToolkit/Graph-Controls#208 · 20 条评论 ·
-
enhancement :sparkles:
难度 2/5 1-3 小时 新手友好度 35/100
-
Area: Providers
难度 2/5 1-3 小时 新手友好度 55/100
CommunityToolkit/Graph-Controls#195 · 1 条评论 ·
-
Area: Providers bug :bug:
难度 4/5 3-5 天 新手友好度 35/100
CommunityToolkit/Graph-Controls#189 · 3 条评论 ·
查看 CommunityToolkit/Graph-Controls 的全部 Issue
相似的 Issue
-
area: core bug help wanted ready
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
area: remote bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
难度 2/5 1-3 小时 新手友好度 70/100
CodeYourFuture/Module-Tools#712 ·
-
A: Mapping P3: Standard T: New Feature
难度 2/5 1-3 小时 新手友好度 68/100
space-wizards/space-station-14#46878 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 60/100
CommunityToolkit/Windows#896 · 2 条评论 ·