我正在尝试将 Azure App 洞察服务集成到服务结构应用程序中以进行日志记录和检测。我在本地 VM 上运行结构代码。我完全按照这里的文档[场景 2]。docs.microsoft.com 上的其他资源似乎也表明了相同的步骤。[例如:https ://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-diagnostics-event-aggregation-eventflow 出于某种原因,我在 App 洞察力中看不到任何事件条目。当我这样做时,代码中没有错误:
ServiceEventSource.Current.ProcessedCountMetric("synced",sw.ElapsedMilliseconds, crc.DataTable.Rows.Count);
eventflowconfig.json 内容
{ “输入”:[ { “类型”:“事件源”, “来源”:[ { "providerName": "Microsoft-ServiceFabric-Services" }, { "providerName": "Microsoft-ServiceFabric-Actors" }, { "providerName": "mystatefulservice" } ] } ], “过滤器”:[ { “类型”:“下降”, “包括”:“级别 == 详细” } ], “输出”:[ { "type": "ApplicationInsights", //(将以下值替换为您的 AI 资源的检测键) "instrumentationKey": "XXXXXXXXXXXXXXXXXXXXXX", “过滤器”:[ { “类型”:“元数据”, “元数据”:“指标”, "include": "ProviderName == mystatefulservice && EventName == ProcessedCountMetric", "操作属性": "操作", "elapsedMilliSecondsProperty": "elapsedMilliSeconds", “记录计数属性”:“记录计数” } ] } ], “schemaVersion”:“2016-08-11” }
在 ServiceEventSource.cs
[Event(ProcessedCountMetricEventId, Level = EventLevel.Informational)]
public void ProcessedCountMetric(string operation, long elapsedMilliSeconds, int recordCount)
{
if (IsEnabled())
WriteEvent(ProcessedCountMetricEventId, operation, elapsedMilliSeconds, recordCount);
}
编辑 从结构状态服务中的“Program.cs”添加诊断管道代码
using (var diagnosticsPipeline =
ServiceFabricDiagnosticPipelineFactory.CreatePipeline($"{ServiceFabricGlobalConstants.AppName}-mystatefulservice-DiagnosticsPipeline")
)
{
ServiceRuntime.RegisterServiceAsync("mystatefulserviceType",
context => new mystatefulservice(context)).GetAwaiter().GetResult();
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id,
typeof(mystatefulservice).Name);
// Prevents this host process from terminating so services keep running.
Thread.Sleep(Timeout.Infinite);
}