Информация о приложении Не отображаются сообщения Trace.TraceInformation - PullRequest
0 голосов
/ 06 июня 2018

У меня есть .net core web api project.Я просто пытаюсь, чтобы мои операторы трассировки, как показано ниже, появлялись в приложениях:

Trace.TraceInformation("Hello World!");

Я вижу журнал в моем окне вывода при отладке, но после развертывания я не вижу ни одного измои операторы трассировки в журналах .... Почему?

У меня есть пакеты Microsoft.ApplicationInsights.AspNetCore и Microsoft.ApplicationInsights.TraceListener.

Я знаю, что понимание приложения настроено, потому что запросы появляются, и я получаю одно сообщение трассировки из показателей производительности, которые не собираются (см. сообщение трассировки ниже):

AI: Error collecting 3 of the configured performance counters. Please check the configuration.
Counter \ASP.NET Applications(??APP_W3SVC_PROC??)\Requests/Sec: Failed to perform the first read for performance counter. Please make sure it exists. Category: ASP.NET Applications, counter: Requests/Sec, instance MyAPI.exe
Counter \ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time: Failed to perform the first read for performance counter. Please make sure it exists. Category: ASP.NET Applications, counter: Request Execution Time, instance MyAPI.exe
Counter \ASP.NET Applications(??APP_W3SVC_PROC??)\Requests In Application Queue: Failed to perform the first read for performance counter. Please make sure it exists. Category: ASP.NET Applications, counter: Requests In Application Queue, instance 

Ответы [ 2 ]

0 голосов
/ 11 июня 2018

Microsoft.ApplicationInsights.TraceListener можно использовать в проектах .NET Core, так как он нацелен на NETSTANDARD1.3, но настройку необходимо выполнить вручную (как указано в посте выше).

Ниже приведены мои ConfigureServices методы в Startup классе.

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry("ikey"); /* This enables entire application insights auto-collection. If you don't want anything but the traces, then ikey can be set in TelemetryConfiguration.Active.InstrumentationKey as the above console app example. */
    services.AddMvc();
    Trace.Listeners.Add(new ApplicationInsightsTraceListener());
}
0 голосов
/ 11 июня 2018

После добавления пакета TraceListner для полной версии .NET добавляется следующий раздел:

<system.diagnostics>
    <trace autoflush="true" indentsize="0">
        <listeners>
            <add name="myAppInsightsListener"
                type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener"/>
        </listeners>
    </trace>
</system.diagnostics>

Поскольку автоматической регистрации для .NET Core не существует, похоже, что это вопрос регистрации ApplicationInsightsTraceListener:

Trace.Listeners.Add(new ApplicationInsightsTraceListener());

Вот полное консольное приложение (должно работать и для других типов), которое захватывает все три трассировки (через TraceError, TraceInformation и TrackTrace):

using System;
using System.Diagnostics;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.TraceListener;

namespace CoreConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            TelemetryConfiguration.Active.InstrumentationKey =
                "<your ikey>";

            Console.WriteLine("Hello World!");

            Trace.Listeners.Add(new ApplicationInsightsTraceListener());
            Trace.TraceError("my error");
            Trace.TraceInformation("my information");

            TelemetryClient client = new TelemetryClient();
            client.TrackTrace("Demo application starting up.");

            Console.ReadKey();
        }
    }
}
...