【发布时间】:2020-01-24 14:07:57
【问题描述】:
我有以下设置:
- ASP.NET Core 3.1 应用程序,部署到 Azure 应用服务
- 通过
IdentityServer4.AspNetIdentity包使用IDS4,版本3.1.0 - 在
Program.cs中,它从Microsoft.ApplicationInsights.AspNetCore版本2.5.1 调用.UseApplicationInsights() -
DefaultLogLevel设置为Warning - 我的
Error.cshtml显示Activity.Current?.Id ?? HttpContext.TraceIdentifier
这会正确记录来自应用服务的几件事,但我找不到由 IDS4 报告的在 OpenID/OAuth2 协议级别的任何错误(例如,请求的无效范围等)。例如,我可以找到这样的东西:
requests
| where cloud_RoleName == 'my-identity-server-4-role'
| order by timestamp desc
| where url contains 'errorId'
| limit 100
这是有道理的,因为我在登录时遇到了一些(其他)问题,其中隐式流静默刷新失败并重定向到问题 url,例如 https://my-identity-domain.example.org/home/error?errorId=some-long-string-here。该页面向我显示了一个错误页面,说明我可以在我的机器上打开 DeveloperExceptionPage 功能,或者我可以使用:
请求 ID:|123aaac2c1cccf4eb3333411aaa183da7e.bba43cca1_
现在我尝试在 AppInsights 中查找 requests 条目
-
| where id contains "123aaac2c"或 -
| where operation_Id contains "123aaac2c"或 -
| where operation_ParentId contains "123aaac2c"或 -
| where session_Id contains "123aaac2c"或 | where itemId contains "123aaac2c"| where problemId contains "123aaac2c"
exceptions 也类似,其中任何 id 字段都包含我的部分 id。但我似乎找不到结果。
我做错了什么?我还在找错地方吗?或者我应该以某种方式增加日志级别?还是我需要在某处添加代码来配置 IdentityServer4 来记录这些东西?
注意:如果我从控制台本地运行我的应用程序,我确实会看到输出流错误。例如,我在启动中添加了_logger.LogError("test error"),并将我的 SPA 配置为使用我的本地 IDS,但范围不正确,我看到了以下输出:
fail: MyApp.Identity.Startup[0]
test error
Hosting environment: Development
Content root path: C:\git\my-app\MyApp.Identity
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
fail: IdentityServer4.Validation.ScopeValidator[0]
Invalid scope: triggererroridwithinvalidscope
fail: IdentityServer4.Endpoints.AuthorizeEndpoint[0]
Request validation failed
第一个错误只是检查正常错误是如何记录的,第二个错误是模拟我的实际问题(触发errorId 页面,如我的问题前面提到的)。
简而言之,我确实看到通过 ASP.NET Core 日志记录在控制台上记录的内容,但我在 AppInsights 中找不到它们。
注意:我进一步研究了 IdentityServer4 如何进行日志记录,as documented 它使用 ASP.NET Core 默认日志系统进行日志记录,例如注入来自 Microsoft 的 Abstractions 的 ILogger<T>,然后使用一些辅助方法调用 (for example):
var details = new TokenRequestValidationLog(_validatedRequest);
// abbreviated snippet
_logger.Log(LogLevel.Error, "Some message" + ", details: {@details}", details);
也许这没有出现在 AppInsights 中,因为它没有合适的地方?它不是 Trace,不是 Request,也没有真正的 Exception?
【问题讨论】:
-
几个月后,今天重新审视了我们的生产设置。仍然无法在 AppInsights 中找到这些错误,也找不到任何使其正常工作的方法。 ????
标签: c# asp.net-core identityserver4