我有一个使用在 Service Fabric 上运行的 EventFlow 的 ETW 侦听器。
这是我的配置文件(eventFlowConfig.json):
{
"inputs": [
{
"type": "ETW",
"sessionNamePrefix": "MyListenerService",
"cleanupOldSessions": true,
"reuseExistingSession": true,
"providers": [
{
"providerName": "Provider0"
}
]
}
],
"filters": [],
"outputs": [
{
"type": "CustomOutput"
}
],
"schemaVersion": "2018-04-04",
"extensions": [
{
"category": "outputFactory",
"type": "CustomOutput",
"qualifiedTypeName": "MyNamespace.EventFlow.Outputs.CustomOutputFactory, MyAssembly"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的切入点:
private static void Main()
{
try
{
string configurationFileName = "eventFlowConfig.json";
using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("MyService", configurationFileName))
{
ServiceRuntime.RegisterServiceAsync("MyServiceType",
context => new Service(context)).GetAwaiter().GetResult();
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用事件源(Microsoft.Diagnostics.EventFlow.Inputs.EventSource)来创建由事件流(Microsoft.Diagnostic.EventFlow)处理的事件,并将其输出传递给Application Insights(Microsoft.Diagnostics.EventFlow) .Outputs.ApplicationInsights)进行分析.
事件流库似乎要求我将完整的System.Exception对象传递给事件流,以便在Application Insights中将其成功分类为异常事件.
这是我在事件流程中使用的过滤器,用于我的异常:
{
"type": "metadata",
"metadata": "exception",
"include": "EventId == 21",
"exceptionProperty": "shark"
}
Run Code Online (Sandbox Code Playgroud)
这是我的方法,我目前正在生成我希望处理事件流的事件.目前这确实出现在应用程序见解中,但我相信我已经很难实现它,因为我在运行时在输出窗口中看到下面的消息.
Event方法的参数与WriteEvent方法的参数不匹配.这可能导致事件显示不正确.
private const int TestExceptionEventId = 21;
[NonEvent]
public void TestException(string operationType, Exception ex)
{
string shark = ex.ToString();
TestException(operationType, shark);
WriteEvent(TestExceptionEventId, operationType, ex);
}
[Event(TestExceptionEventId, Level = EventLevel.Error, Message = "{0} - {1}, {2}", Keywords = Keywords.Exception)]
public void TestException(string operationType, string shark)
{
}
Run Code Online (Sandbox Code Playgroud)
以下是触发日志记录事件的方法:
//EXCEPTION
//id = 21
try
{
int value = 1 / int.Parse("0");
}
catch …Run Code Online (Sandbox Code Playgroud) .net c# event-flow etw-eventsource azure-application-insights