本文整理汇总了C#中Microsoft.ApplicationInsights.TelemetryClient.IsEnabled方法的典型用法代码示例。如果您正苦于以下问题:C# TelemetryClient.IsEnabled方法的具体用法?C# TelemetryClient.IsEnabled怎么用?C# TelemetryClient.IsEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.ApplicationInsights.TelemetryClient
的用法示例。
在下文中一共展示了TelemetryClient.IsEnabled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsEnabledReturnsTrueIfTelemetryTrackingIsEnabledInConfiguration
public void IsEnabledReturnsTrueIfTelemetryTrackingIsEnabledInConfiguration()
{
var configuration = new TelemetryConfiguration { DisableTelemetry = false };
var client = new TelemetryClient(configuration);
Assert.True(client.IsEnabled());
}
示例2: OnException
/// <summary>
/// Implement OnException method of IExceptionFilter which will be invoked
/// for all unhandled exceptions
/// </summary>
/// <param name="context"></param>
public void OnException(ExceptionContext context)
{
this._logger.LogError("MatterCenterExceptionFilter", context.Exception);
var stackTrace = new StackTrace(context.Exception, true);
StackFrame stackFrameInstance = null;
if(stackTrace.GetFrames().Length>0)
{
for(int i=0; i< stackTrace.GetFrames().Length; i++)
{
if(stackTrace.GetFrames()[i].ToString().Contains("Microsoft.Legal.Matter"))
{
stackFrameInstance = stackTrace.GetFrames()[i];
break;
}
}
}
//Create custom exception response that needs to be send to client
var response = new ErrorResponse()
{
Message = context.Exception.Message,
StackTrace = context.Exception.ToString(),
Description = "Error occured in the system. Please contact the administrator",
//Exception = context.Exception.ToString(),
LineNumber = stackFrameInstance?.GetFileLineNumber(),
MethodName = stackFrameInstance?.GetMethod().Name,
ClassName = stackFrameInstance?.GetMethod().DeclaringType.Name,
ErrorCode = ((int)HttpStatusCode.InternalServerError).ToString()
};
//Create properties that need to be added to application insights
var properties = new Dictionary<string, string>();
properties.Add("StackTrace", response.StackTrace);
properties.Add("LineNumber", response.LineNumber.ToString());
properties.Add("MethodName", response.MethodName.ToString());
properties.Add("ClassName", response.ClassName.ToString());
properties.Add("ErrorCode", response.ErrorCode.ToString());
//Create Telemetry object to add exception to the application insights
var ai = new TelemetryClient();
ai.InstrumentationKey = instrumentationKey;
if(ai.IsEnabled())
{
//add exception to the Application Insights
ai.TrackException(context.Exception, properties);
}
//Send the exceptin object to the client
context.Result = new ObjectResult(response)
{
StatusCode = (int)HttpStatusCode.InternalServerError,
DeclaredType = typeof(ErrorResponse)
};
}