我正在创建一个.Net Standard 2.0 Nuget包,并且我想对该版本执行静态代码分析。但是,当我添加Microsoft.CodeAnalysis.FxCopAnalyzers程序包时,它将成为运行时依赖项,因此任何引用我的Nuget程序包的项目也都将安装分析器。我认为调用代码应该解决这些问题。
无论如何,有什么办法可以防止这种依赖性被强制执行?
我花了一段时间尝试 RequestTelemetry 工作。当我第一次使用它时它确实如此,但奇怪的是每当抛出异常时它就停止工作。我已阅读使用Application Insights 进行自定义事件和指标以及自定义操作跟踪的文档,并尝试添加所有最佳实践以查看是否可以再次显示结果。我正在使用 .NET Core 3.1 和 Microsoft.ApplicationInsights.AspNetCore 2.14.0。
Web 应用程序的设置在 Startup.cs 中如下所示
services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions {
EnableAdaptiveSampling = false
});
Run Code Online (Sandbox Code Playgroud)
我在控制器后操作中进行了遥测。我意识到 Application Insights 已经在跟踪它的后操作,但我想看看是否可以跟踪内部方法。这是我的控制器中的代码:
public MyController(IMyService myService, TelemetryClient telemetryClient, ILogger<MyController> logger) {
_myService = myService;
_telemetryClient = telemetryClient;
_logger = logger;
}
[HttpPost]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> PostAsync([FromBody] MyModel model) {
using var scope = _logger.BeginScope(new Dictionary<string, object> {
{ $"{nameof(PostAsync)}.Scope", Guid.NewGuid() },
{ nameof(model.Name), model.Name }
});
model.AuthenticatedUserId = User.GetUserIdFromClaims();
var …Run Code Online (Sandbox Code Playgroud)