Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何";齐平;ApplicationInsightStracListener,在控制台应用程序中,在退出时?_C#_.net_Azure_Console Application_Azure Application Insights - Fatal编程技术网

C# 如何";齐平;ApplicationInsightStracListener,在控制台应用程序中,在退出时?

C# 如何";齐平;ApplicationInsightStracListener,在控制台应用程序中,在退出时?,c#,.net,azure,console-application,azure-application-insights,C#,.net,Azure,Console Application,Azure Application Insights,我有一个较旧的控制台应用程序,我正在尝试使用ApplicationInsightStraceSListener将跟踪切换为使用应用程序洞察 如果不在日志末尾添加任意睡眠,我很难获取日志的末尾 我用一个非常简单的控制台应用程序重新创建了如下: static void Main(string[] args) { Trace.TraceInformation("Hello World!"); Thread.Sleep(10000); } 有了睡

我有一个较旧的控制台应用程序,我正在尝试使用ApplicationInsightStraceSListener将跟踪切换为使用应用程序洞察

如果不在日志末尾添加任意睡眠,我很难获取日志的末尾

我用一个非常简单的控制台应用程序重新创建了如下:

    static void Main(string[] args)
    {
        Trace.TraceInformation("Hello World!");
        Thread.Sleep(10000);
    }
有了
睡眠
我可以看到它,没有它我就看不见

我尝试了几种不同的睡眠方式,比如

        System.Diagnostics.Trace.Flush();

我正在使用开箱即用的ApplicationInsights.config(我的指令插入键除外)

这是packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.ApplicationInsights" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.TraceListener" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.8.1" targetFramework="net472" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.5.0" targetFramework="net472" />
</packages>

不幸的是,目前没有好的解决办法。只有在所有数据都被持久化后才会返回的ask for Flush处于

一种选择是用InMemoryChannel替换遥测通道。然后Flush将保证数据被发送到端点。但如果端点不可用,此通道不会重试,因此仍有可能丢失数据

另一个选择是提出自己的遥测通道。但这可能需要大量工作才能使其可靠


当控制台应用程序返回时,ServerTelemetryChannel将重新发送数据。但不确定这是否有助于您的场景。

谢谢。这就是我所发现的,尽管在实践中,我从未让ServerTelemetryChannel在控制台应用程序返回时重新发送数据。一个选项是在github上打开一个新问题,不为控制台应用程序重新发送数据。团队将进行调查。唯一对我们有效的方法是添加
线程.Sleep(45000)。这不是一个很好的解决方案,但它修复了我们所有的控制台应用程序。
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.ApplicationInsights" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.TraceListener" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.8.1" targetFramework="net472" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.8.1" targetFramework="net472" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.5.0" targetFramework="net472" />
</packages>
var channel = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.TelemetryChannel as ServerTelemetryChannel;
channel.MaxTelemetryBufferDelay = TimeSpan.FromSeconds(.5);
Thread.Sleep(channel.MaxTelemetryBufferDelay);