programing

Azure WebJob과 함께 Azure 애플리케이션 통찰력 사용

oldcodes 2023. 4. 29. 09:52
반응형

Azure WebJob과 함께 Azure 애플리케이션 통찰력 사용

Azure 설명서에서는 Azure Application Insight를 ASP와 같은 다양한 애플리케이션 유형에 통합하는 많은 예를 다룹니다.NET, Java 등그러나 설명서에는 Application Insight를 Azure WebJob에 통합하는 예는 나와 있지 않습니다.

콘솔 앱으로 구축된 Azure WebJob에 Azure Application Insight를 통합하는 방법을 다룬 예제 또는 기사에 대한 링크가 있습니까?

Application Insights를 통해 이벤트와 메트릭을 추적하는 콘솔 애플리케이션을 작성했는데, 다음과 같은 NuGet 패키지를 추가하면 WebJob도 크게 다르지 않을 것으로 판단했습니다.

  • 마이크로소프트.어플통찰력
  • 마이크로소프트.어플통찰력.TraceListener(필요하지 않을 수 있음)

나의ApplicationInsights.config다음과 같이 표시됩니다.

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
    <TelemetryModules>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights" />
    </TelemetryModules>
</ApplicationInsights>

그리고 간단한 프로그램은 다음과 같습니다.

TelemetryConfiguration.Active.InstrumentationKey = "the_key";
TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true;

var tc = new TelemetryClient();
tc.TrackRequest("Track Some Request", DateTimeOffset.UtcNow, new TimeSpan(0, 0, 3), "200", true);
tc.TrackMetric("XYZ Metric", 100);
tc.TrackEvent("Tracked Event");

tc.Flush(); //need to do this, otherwise if the app exits the telemetry data won't be sent

Windows Desktop 애플리케이션, 서비스 작업자 역할에 대한 애플리케이션 인사이트도 있습니다.

위의 답변이 2살이기 때문에 그 이후로 많은 것들이 바뀌었습니다.이제 애플리케이션 인사이트와 Azure 웹 작업을 통합할 수 있는 너겟 패키지가 있습니다.아래 패키지를 설치해야 합니다.

  1. 마이크로소프트.애저, 웹잡스로깅.어플통찰력(현재 베타 버전)
  2. 마이크로소프트.내선 번호.로깅
  3. 마이크로소프트.내선 번호.로깅.콘솔

아래와 같이 작업 호스트 구성을 구성합니다.

string instrumentationKey = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY");
if (!string.IsNullOrEmpty(instrumentationKey))
{
      // build up a LoggerFactory with ApplicationInsights and a Console Logger
       config.LoggerFactory = new LoggerFactory().AddApplicationInsights(instrumentationKey, null).AddConsole();
       config.Tracing.ConsoleLevel = TraceLevel.Off;
}

여기에서 전체 게시물 보기

언급URL : https://stackoverflow.com/questions/32469014/use-azure-application-insights-with-azure-webjob

반응형