有一些类似的问题,但没有一个真正回答我的问题。 我想使用 Ilogger 记录我的自定义用户日志,但仍保留 Visual Studio“自动”添加的应用程序见解。这在 .Net core 中非常简单(只需在启动时添加 Ilogger),但 .Net Framework 则不然(除非我遗漏了一些东西?)。也许我的做法是错误的?
我想知道是否有人有这个工作,或者我是在浪费时间,应该直接使用 TelemetryClient 吗?
我有 2 个旧的 ASP.Net Framework 4.8 API,都部署到 Azure 应用服务。
app#1 过去曾在 Visual Studio 中通过自动方式添加了 Application Insights。它可以很好地记录遥测数据,但是当我向其中添加 Ilogger 时,它不会记录任何用户日志。
app#2 我只使用 ILogger 并记录我创建的所有日志,但没有自动记录任何内容,也没有遥测(由于应用程序 #1 不起作用,尚未尝试添加它)。
两者都使用 Autofac 进行依赖注入,它有一个扩展允许您使用 Microsoft.Extensions.dependency 注入。像这样:
var builder = new ContainerBuilder();
IServiceCollection services = new ServiceCollection();
services.AddLogging(options =>
{
options.AddApplicationInsights(configureTelemetryConfiguration: (c) => c.ConnectionString = ConfigurationManager.AppSettings["APPLICATIONINSIGHTS_CONNECTION_STRING"],
configureApplicationInsightsLoggerOptions: (o) =>{});
});
builder.Populate(services);
应用程序 #2 工作正常,我创建的所有内容都会记录。
App#1 安装了以下软件包,并在 applicationInsights.config 和日志遥测中包含大量内容,但似乎忽略了我创建的任何日志
<package id="Microsoft.ApplicationInsights" version="2.22.0" targetFramework="net48" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net48" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.22.0" targetFramework="net48" />
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.22.0" targetFramework="net48" />
<package id="Microsoft.ApplicationInsights.TraceListener" version="2.22.0" targetFramework="net48" />
<package id="Microsoft.ApplicationInsights.Web" version="2.22.0" targetFramework="net48" />
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.22.0" targetFramework="net48" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.22.0" targetFramework="net48" />
有什么想法吗?
我确实已正确设置所有过滤器,因此它不会过滤掉用户日志。甚至尝试只输入 Logging:LogLevel:default = Trace
我最终删除了所有应用程序洞察并完全记录并重新进行,现在它工作得很好。一定是搞砸了一些东西,或者可能是应用程序洞察的非常旧的设置不兼容