本文整理汇总了C#中Microsoft.ApplicationInsights.TelemetryClient.TrackException方法的典型用法代码示例。如果您正苦于以下问题:C# TelemetryClient.TrackException方法的具体用法?C# TelemetryClient.TrackException怎么用?C# TelemetryClient.TrackException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.ApplicationInsights.TelemetryClient
的用法示例。
在下文中一共展示了TelemetryClient.TrackException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnException
public override void OnException(ExceptionContext context)
{
base.OnException(context);
if (context != null)
{
try
{
if (context.HttpContext != null && context.Exception != null)
{
// If customError is Off, then AppInsights HTTP module will report the exception. If not, handle it explicitly.
// http://blogs.msdn.com/b/visualstudioalm/archive/2014/12/12/application-insights-exception-telemetry.aspx
if (context.HttpContext.IsCustomErrorEnabled)
{
var telemetryClient = new TelemetryClient();
telemetryClient.TrackException(context.Exception);
}
}
}
catch (Exception exception)
{
context.Exception = new AggregateException("Failed to send exception telemetry.", exception, context.Exception);
}
}
}
示例2: RunJob
public HttpResponseMessage RunJob()
{
var telemetry = new TelemetryClient();
try
{
// トークンの削除
var manager = TokenManager.GetInstance();
manager.CleanExpiredToken();
// 放送していないルームの削除
using (var db = new ApplicationDbContext())
{
var instance = RoomManager.GetInstance();
var liveRoom = db.Rooms.Where(c => c.IsLive);
foreach (var item in liveRoom)
{
if (instance.GetRoomInfo(item.Id) == null)
{
item.IsLive = true;
}
}
db.SaveChanges();
}
return Request.CreateResponse(HttpStatusCode.Accepted);
}
catch (Exception ex)
{
telemetry.TrackException(ex, new Dictionary<string, string>() { { "Method", "RunJob" } }, null);
return Request.CreateResponse(HttpStatusCode.InternalServerError);
}
}
示例3: SendMessage
public static bool SendMessage(ContactAttempt contactAttempt)
{
var telemetry = new TelemetryClient();
bool success;
try
{
var contactInfo = _contactInfoRepository.GetContactInfo(contactAttempt.ProfileId);
MailMessage mailMessage = new MailMessage(contactAttempt.EmailAddress, contactInfo.EmailAddress, contactAttempt.Subject, contactAttempt.Message);
var client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["MailUserName"], ConfigurationManager.AppSettings["MailPassword"]);
client.Send(mailMessage);
telemetry.TrackEvent("EmailSent", GetEmailSentTrackingProperties(contactAttempt, contactInfo));
success = true;
}
catch(Exception ex)
{
telemetry.TrackException(ex);
success = false;
}
return success;
}
示例4: OnException
public override void OnException(ExceptionContext filterContext)
{
if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
{
//If customError is Off, then AI HTTPModule will report the exception
if (filterContext.HttpContext.IsCustomErrorEnabled)
{
string email;
try
{
email = filterContext.HttpContext.User.Identity.Name;
}
catch
{
email = "unknown";
}
var properties = new Dictionary<string, string>();
properties.Add("AzureDayUserEmail", email);
// Note: A single instance of telemetry client is sufficient to track multiple telemetry items.
var ai = new TelemetryClient();
ai.TrackException(filterContext.Exception, properties);
}
}
base.OnException(filterContext);
}
示例5: TelemetryClient
bool IErrorHandler.HandleError(Exception error)
{
//or reuse instance (recommended!). see note above
var ai = new TelemetryClient();
ai.TrackException(error);
return false;
}
示例6: Application_Error
protected void Application_Error()
{
var exception = Server.GetLastError();
var telemetryClient = new TelemetryClient();
telemetryClient.TrackException(exception);
}
示例7: Log
public override void Log(ExceptionLoggerContext context)
{
if (context != null && context.Exception != null)
{//or reuse instance (recommended!). see note above
var ai = new TelemetryClient();
ai.TrackException(context.Exception);
}
base.Log(context);
}
示例8: Log
/// <summary>
/// Logs the unhandled exceptions.
/// </summary>
/// <param name="context">The exception logger context.</param>
public override void Log(ExceptionLoggerContext context)
{
if (context?.Exception != null)
{
var telemetryClient = new TelemetryClient();
telemetryClient.TrackException(context.Exception);
}
base.Log(context);
}
示例9: Log
public override void Log(ExceptionLoggerContext context)
{
if (context != null && context.Exception != null)
{
// Note: A single instance of telemetry client is sufficient to track multiple telemetry items.
var ai = new TelemetryClient();
ai.TrackException(context.Exception);
}
base.Log(context);
}
示例10: 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)
};
}
示例11: CreateConfiguration
private static DecisionServiceConfiguration CreateConfiguration(string settingsUrl)
{
var telemetry = new TelemetryClient();
telemetry.TrackEvent($"DecisionServiceClient created: '{settingsUrl}'");
return new DecisionServiceConfiguration(settingsUrl)
{
InteractionUploadConfiguration = new BatchingConfiguration
{
// TODO: these are not production ready configurations. do we need to move those to C&C as well?
MaxBufferSizeInBytes = 1,
MaxDuration = TimeSpan.FromSeconds(1),
MaxEventCount = 1,
MaxUploadQueueCapacity = 1,
UploadRetryPolicy = BatchUploadRetryPolicy.ExponentialRetry
},
ModelPollFailureCallback = e => telemetry.TrackException(e, new Dictionary<string, string> { { "Pool failure", "model" } }),
SettingsPollFailureCallback = e => telemetry.TrackException(e, new Dictionary<string, string> { { "Pool failure", "settings" } })
};
}
示例12: OnException
public override void OnException(HttpActionExecutedContext context)
{
// Track Exceptions with Application Insights
TelemetryClient telemetryClient = new TelemetryClient();
telemetryClient.TrackException(context.Exception);
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent("An error occurred, please try again or contact the administrator."),
ReasonPhrase = "Critical Exception"
});
}
示例13: Application_Error
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = this.Server.GetLastError();
if (exception == null || exception is OperationCanceledException)
{
return;
}
// Track Exceptions with Application Insights
TelemetryClient telemetryClient = new TelemetryClient();
telemetryClient.TrackException(exception);
}
示例14: OnException
public override void OnException(ExceptionContext filterContext)
{
if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
{
if (filterContext.HttpContext.IsCustomErrorEnabled)
{
var ai = new TelemetryClient();
ai.TrackException(filterContext.Exception);
}
}
base.OnException(filterContext);
}
示例15: OnException
public override void OnException(ExceptionContext filterContext)
{
if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
{
//If customError is Off, then AI HTTPModule will report the exception
if (filterContext.HttpContext.IsCustomErrorEnabled)
{ //or reuse instance (recommended!). see note above
var ai = new TelemetryClient();
ai.TrackException(filterContext.Exception);
}
}
base.OnException(filterContext);
}