2017-02-15 4 views
0

서비스 패브릭 로그에 저장하려면 Trace.Trace* (Information, Warning, Error 등)을 어떻게 설정합니까? 내가 찾은 유일한 옵션은 메시지를 보내려면 ServiceEventSource을 사용하는 것이지만 Trace 문에서 멀리 이동하려면 많은 코드를 수정해야합니다.서비스 패브릭 - 로깅되지 않는 추적 문

Trace 문을 ServiceEventSource로 전달하는 데 사용할 수있는 수신기가 있습니까? 아니면 더 단순한가?

+1

아마도 https://github.com/Azure/diagnostics-eventflow를 사용하여 추적 메시지를 ServiceEventSource로 재 라우팅 할 수 있습니다. EventSource는 기본적으로 제공되지 않기 때문에 출력을 작성해야하지만 간단합니다. –

+0

감사합니다. 나는 그 첫번째 일을 내일 시도 할 것입니다! –

답변

2

EventFlow (Peter Bons의 의견에서 언급)과 Application Insights을 조합하면 좋은 해결책이 될 수 있습니다. EventFlow를 설정하여 기존 Trace 문을 청취 한 다음 Application Insighs로 전달하여 서비스 실행을 모니터링 할 수 있습니다.

EventFlow를 설정하는 것은 매우 쉽습니다. 서비스 프로젝트에 NuGet Microsoft.Diagnostics.EventFlow을 추가하기 만하면됩니다. 방금 설치 응용 프로그램 통찰력 당신의 푸른 계정의 인스턴스가 AI의 하나에 instrumentationKey을 변경

{ 
"inputs": [ 
    { 
     "type": "Trace", 
     "traceLevel": "Warning" 
    } 
], 
"filters": [], 
"outputs": [ 
    { 
     "type": "ApplicationInsights", 
     "instrumentationKey": "00000000-0000-0000-0000-000000000000" 
    } 
], 
"schemaVersion": "2016-08-11", 
"extensions": [] 

} 이제

: 그런 다음 eventflowconfig.json에서 출력으로 입력 및 응용 프로그램 통찰력으로 추적을 추가 예. 당신이 (당신이 당신의 흔적에있는 정보의 유형이있는 경우) 당신이 그것을 시각화 또는 특정을 검색 할 수 있습니다 당신의 흔적에서 특정 요청 및 메트릭 데이터를 추출하기 위해 EventFlow 구성을 수정 시작할 수 후

application insights settings

AI 대시 보드의 추적 유형.

Application Insights는 기본적으로 7 일 동안 만 로그를 보존합니다. 추적 시간을 길게 잡으려면 AI 계층을 변경할 수 있으며 activate Continuous Export 수 있습니다.

-1
namespace MassProcessing 
{ 
    internal static class Program 
    { 
     /// <summary> 
     /// This is the entry point of the service host process. 
     /// </summary> 
     private static void Main() 
     { 
      try 
      { 
       // The ServiceManifest.XML file defines one or more service type names. 
       // Registering a service maps a service type name to a .NET type. 
       // When Service Fabric creates an instance of this service type, 
       // an instance of the class is created in this host process. 
       using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("EngageServiceFabric-MassProcessing-DiagnosticsPipeline")) 
       { 
        ServiceRuntime.RegisterServiceAsync("MassProcessingType", 
        context => new MassProcessing(context)).GetAwaiter().GetResult(); 

        ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(MassProcessing).Name); 

        // Prevents this host process from terminating so services keep running. 
        Thread.Sleep(Timeout.Infinite); 
       } 
      } 
      catch (Exception e) 
      { 
       ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); 
       throw; 
      } 
     } 
    } 
}