代码之家  ›  专栏  ›  技术社区  ›  punkologist

在中同时使用ILogger和Application Insights遥测。Net框架

  •  0
  • punkologist  · 技术社区  · 2 年前

    有几个类似的问题,但没有一个真正回答我的问题。 我想使用Ilogger来记录我的自定义用户日志,但仍然保留Visual Studio“自动”添加的应用程序见解。这是非常直接的。Net-core(只需在启动时添加Ilogger)但是。Net Framework没有那么多(除非我遗漏了什么?)。也许我做错了?

    我想知道是否有人在工作,或者我是在浪费时间,应该直接使用TelemetryClient?

    我有两个旧ASP。Net Framework 4.8 Apis,两者都部署到Azure应用程序服务。

    在过去的某个时候,应用程序#1已经在Visual studio中自动添加了Application Insights。它可以很好地记录遥测,但当我向它添加Ilogger时,它不会记录任何用户日志。

    应用程序#2我只使用ILogger并记录我创建的所有日志,但没有自动记录任何内容,也没有遥测(由于应用程序#1不工作,我还没有尝试添加它)。

    两者都使用Autofac进行依赖项注入,它有一个扩展,允许您使用Microsoft。扩展。与之相关的依赖性注入。如下所示:

       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这工作得很好,所有我创建的日志。

    应用程序#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

    0 回复  |  直到 2 年前
        1
  •  0
  •   punkologist    2 年前

    我最终完全删除了所有的应用程序见解和日志记录,并重新进行了它们,现在它工作得很好。。一定是搞砸了什么,或者可能是应用程序洞察的旧设置不兼容