I'm trying to use Event Source (Microsoft.Diagnostics.EventFlow.Inputs.EventSource) to create an event that is handled by Event Flow (Microsoft.Diagnostic.EventFlow) and whose output is passed to Application Insights (Microsoft.Diagnostics.EventFlow.Outputs.ApplicationInsights) for analysis.
The event flow library seems to require that I pass the full System.Exception object to event flow in order to for it to be successfully classified as an exception event in Application Insights.
Here is the filter I am using in Event Flow for my exception:
{
"type": "metadata",
"metadata": "exception",
"include": "EventId == 21",
"exceptionProperty": "shark"
}
Here are my methods where I am currently generating the Event which I wish to handle with event flow. Currently this does appear inside application insights however I belie I have implemented it poorly as I see message below in the output window during runtime.
The parameters to the Event method do not match the parameters to the WriteEvent method. This may cause the event to be displayed incorrectly.
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)
{
}
Here is the method where the logging event is fired:
//EXCEPTION
//id = 21
try
{
int value = 1 / int.Parse("0");
}
catch (DivideByZeroException exception)
{
//id = 21
_eventSource.TestException("hello", exception);
}`
Can anyone provide some clarity on the correct way to implement this and what is the correct way to pass an System.Exception Object through Event Flow and Onto Application Insights.
Many Thanks.