【发布时间】:2020-03-10 11:44:37
【问题描述】:
我正在尝试自定义我们向用户显示哨兵事件的方式。
我的appsettings是这样的:
"Sentry": {
"DSN": "...",
"IncludeRequestPayload": true,
"SendDefaultPii": true,
"MinimumBreadcrumbLevel": "Debug",
"MinimumEventLevel": "Warning",
"AttachStackTrace": true,
"Debug": true,
"DiagnosticsLevel": "Error"
},
我将工厂注册为单例(我也尝试过瞬态)
services.AddSingleton<Sentry.AspNetCore.IUserFactory, MySentryUserFactory>();
在我的启动中,我这样调用 UseSentry:
public static void Main(string[] args)
{
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) => ...)
.UseKestrel(options => ...)
.UseStartup<Startup>()
.UseSentry()
.Build().Run();
}
在 MySentryUserFactory 中,我没有看到它的效果,所以我在最顶部放置了一个 Console.WriteLine:
public User Create(HttpContext context)
{
Console.WriteLine("------------------- I am using the custom userfactory");
...
}
所以我通过手动调用 SentrySdk 来测试它:
Exception e = new Exception("blah");
SentrySdk.CaptureException(e);
但是当我运行它时,我在控制台中看不到打印输出语句。然后,当我进入哨兵仪表板时,我看到了我正在测试的错误事件,并且没有显示用户(没有执行 IUserFactory 设置的操作)。
【问题讨论】: