当前位置: 首页>>代码示例>>C#>>正文


C# TelemetryClient.TrackException方法代码示例

本文整理汇总了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);
                }
            }
        }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:25,代码来源:SendErrorsToTelemetryAttribute.cs

示例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);
            }
        }
开发者ID:VSShare,项目名称:VSShare-Server,代码行数:32,代码来源:JobController.cs

示例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;
        }
开发者ID:michaelquinn5280,项目名称:Portfolio,代码行数:25,代码来源:MailHelper.cs

示例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);
		}
开发者ID:AzureDay,项目名称:2016-WebSite,代码行数:27,代码来源:ApplicationInsightHandleErrorAttribute.cs

示例5: TelemetryClient

        bool IErrorHandler.HandleError(Exception error)
        {
            //or reuse instance (recommended!). see note above
            var ai = new TelemetryClient();

            ai.TrackException(error);
            return false;
        }
开发者ID:tRAKALOFF,项目名称:seguridadcorporativa,代码行数:8,代码来源:AiLogExceptionAttribute.cs

示例6: Application_Error

        protected void Application_Error()
        {
            var exception = Server.GetLastError();

            var telemetryClient = new TelemetryClient();

            telemetryClient.TrackException(exception);
        }
开发者ID:bekk,项目名称:TrhNetMicro,代码行数:8,代码来源:Global.asax.cs

示例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);
 }
开发者ID:QualityConsultingTeam,项目名称:Cancha,代码行数:9,代码来源:ExceptionLogger.cs

示例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);
        }
开发者ID:Microsoft,项目名称:Appsample-Photosharing,代码行数:14,代码来源:ApplicationInsightsExceptionLogger.cs

示例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);
 }
开发者ID:Azure-Samples,项目名称:MyDriving,代码行数:10,代码来源:Startup.MobileApp.cs

示例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)                
            };
        }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:59,代码来源:MatterCenterExceptionFilter.cs

示例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" } })
            };
        }
开发者ID:xornand,项目名称:mwt-ds-web-api,代码行数:20,代码来源:DecisionServiceClientFactory.cs

示例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"
            });
        }
开发者ID:aserplus,项目名称:itty-bitty-url,代码行数:12,代码来源:ExceptionHandlingAttribute.cs

示例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);
        }
开发者ID:aserplus,项目名称:itty-bitty-url,代码行数:12,代码来源:Global.asax.cs

示例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);
        }
开发者ID:hendrikmaarand,项目名称:vso.io,代码行数:13,代码来源:ApplicationInsightsHandleErrorAttribute.cs

示例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);
 }
开发者ID:cubitouch,项目名称:Barly,代码行数:13,代码来源:AiHandleErrorAttribute.cs


注:本文中的Microsoft.ApplicationInsights.TelemetryClient.TrackException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。