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


C# Error.ToJson方法代码示例

本文整理汇总了C#中Error.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# Error.ToJson方法的具体用法?C# Error.ToJson怎么用?C# Error.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Error的用法示例。


在下文中一共展示了Error.ToJson方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogError

        /// <summary>
        /// Logs the error to SQL
        /// If the rollup conditions are met, then the matching error will have a DuplicateCount += @DuplicateCount (usually 1, unless in retry) rather than a distinct new row for the error
        /// </summary>
        /// <param name="error">The error to log</param>
        protected override void LogError(Error error)
        {
            using (var c = GetConnection())
            {
                if (RollupThreshold.HasValue && error.ErrorHash.HasValue)
                {
                    var queryParams = new DynamicParameters(new
                        {
                            error.DuplicateCount,
                            error.ErrorHash,
                            ApplicationName,
                            minDate = DateTime.UtcNow.Add(RollupThreshold.Value.Negate())
                        });
                    queryParams.Add("@newGUID", dbType: DbType.Guid, direction: ParameterDirection.Output);
                    var count = c.Execute(@"
Update Exceptions 
   Set DuplicateCount = DuplicateCount + @DuplicateCount,
       @newGUID = GUID
 Where Id In (Select Top 1 Id
                From Exceptions 
               Where ErrorHash = @ErrorHash
                 And ApplicationName = @ApplicationName
                 And DeletionDate Is Null
                 And CreationDate >= @minDate)", queryParams);
                    // if we found an error that's a duplicate, jump out
                    if (count > 0)
                    {
                        error.GUID = queryParams.Get<Guid>("@newGUID");
                        return;
                    }
                }

                error.FullJson = error.ToJson();

                c.Execute(@"
Insert Into Exceptions (GUID, ApplicationName, MachineName, CreationDate, Type, IsProtected, Host, Url, HTTPMethod, IPAddress, Source, Message, Detail, StatusCode, SQL, FullJson, ErrorHash, DuplicateCount)
Values (@GUID, @ApplicationName, @MachineName, @CreationDate, @Type, @IsProtected, @Host, @Url, @HTTPMethod, @IPAddress, @Source, @Message, @Detail, @StatusCode, @SQL, @FullJson, @ErrorHash, @DuplicateCount)",
                    new {
                            error.GUID,
                            ApplicationName = error.ApplicationName.Truncate(50),
                            MachineName = error.MachineName.Truncate(50),
                            error.CreationDate,
                            Type = error.Type.Truncate(100),
                            error.IsProtected,
                            Host = error.Host.Truncate(100),
                            Url = error.Url.Truncate(500),
                            HTTPMethod = error.HTTPMethod.Truncate(10), // this feels silly, but you never know when someone will up and go crazy with HTTP 1.2!
                            error.IPAddress,
                            Source = error.Source.Truncate(100),
                            Message = error.Message.Truncate(1000),
                            error.Detail,
                            error.StatusCode,
                            error.SQL,
                            error.FullJson,
                            error.ErrorHash,
                            error.DuplicateCount
                        });
            }
        }
开发者ID:stijnherreman,项目名称:StackExchange.Exceptional,代码行数:64,代码来源:SQLErrorStore.cs

示例2: LogError

        /// <summary>
        ///     Logs the error to SQL
        ///     If the rollup conditions are met, then the matching error will have a DuplicateCount += @DuplicateCount (usually 1,
        ///     unless in retry) rather than a distinct new row for the error
        /// </summary>
        /// <param name="error">The error to log</param>
        protected override void LogError(Error error)
        {
            using (var c = GetConnection())
            {
                if (RollupThreshold.HasValue && error.ErrorHash.HasValue)
                {
                    // Look for an existing exception 
                    IEnumerable<Error> existingException = c.Query<Error>(@"Select * from Exceptions Where ErrorHash = @ErrorHash
                                                     And ApplicationName = @ApplicationName
                                                     And DeletionDate Is Null
                                                     And CreationDate >= @minDate limit 1 ",
                        new
                        {
                            error.ErrorHash,
                            ApplicationName = error.ApplicationName.Truncate(50),
                            minDate = DateTime.UtcNow.Add(RollupThreshold.Value.Negate())
                        });


                    if (existingException.Any())
                    {
                        // Update the count and move on
                        error.GUID = existingException.First().GUID;
                        c.Execute("Update Exceptions set DuplicateCount = DuplicateCount + @DuplicateCount where ID = @id", new {error.DuplicateCount, id = existingException.First().Id});
                    }
                    else
                    {
                        error.FullJson = error.ToJson();

                        c.Execute(@"
Insert Into Exceptions (GUID, ApplicationName, MachineName, CreationDate, Type, IsProtected, Host, Url, HTTPMethod, IPAddress, Source, Message, Detail, StatusCode, `SQL`, FullJson, ErrorHash, DuplicateCount)
Values (@GUID, @ApplicationName, @MachineName, @CreationDate, @Type, @IsProtected, @Host, @Url, @HTTPMethod, @IPAddress, @Source, @Message, @Detail, @StatusCode, @SQL, @FullJson, @ErrorHash, @DuplicateCount)",
                            new
                            {
                                error.GUID,
                                ApplicationName = error.ApplicationName.Truncate(50),
                                MachineName = error.MachineName.Truncate(50),
                                error.CreationDate,
                                Type = error.Type.Truncate(100),
                                error.IsProtected,
                                Host = error.Host.Truncate(100),
                                Url = error.Url.Truncate(500),
                                HTTPMethod = error.HTTPMethod.Truncate(10), // this feels silly, but you never know when someone will up and go crazy with HTTP 1.2!
                                error.IPAddress,
                                Source = error.Source.Truncate(100),
                                Message = error.Message.Truncate(1000),
                                error.Detail,
                                error.StatusCode,
                                error.SQL,
                                error.FullJson,
                                error.ErrorHash,
                                error.DuplicateCount
                            });
                    }
                }
            }
        }
开发者ID:hongduo168,项目名称:StackExchange.Exceptional,代码行数:63,代码来源:MySQLErrorStore.cs

示例3: LogError

        /// <summary>
        ///     Logs the error to SQL
        ///     If the rollup conditions are met, then the matching error will have a DuplicateCount += @DuplicateCount (usually 1,
        ///     unless in retry) rather than a distinct new row for the error
        /// </summary>
        /// <param name="error">The error to log</param>
        protected override void LogError(Error error)
        {
            using (var c = GetConnection())
            {
                if (RollupThreshold.HasValue && error.ErrorHash.HasValue)
                {
                    var queryParams = new DynamicParameters(new
                    {
                        error.DuplicateCount,
                        error.ErrorHash,
                        ApplicationName = error.ApplicationName.Truncate(50),
                        minDate = DateTime.UtcNow.Add(RollupThreshold.Value.Negate())
                    });
                    var count = c.Execute(@"
                    Update Exceptions 
                      Set DuplicateCount = DuplicateCount + @DuplicateCount
                    Where ErrorHash = @ErrorHash
                    And ApplicationName = @ApplicationName
                    And DeletionDate Is Null
                    And CreationDate >= @minDate limit 1", queryParams);
                    // if we found an exception that's a duplicate, jump out
                    if (count > 0)
                    {
                        // MySQL .NET Connector doesn't support OUT params, so we need to query for the guid.
                        error.GUID = c.Query<Guid>(@"Select guid from Exceptions 
                                Where ErrorHash = @ErrorHash
                                And ApplicationName = @ApplicationName
                                And DeletionDate Is Null
                                And CreationDate >= @minDate limit 1 ", queryParams).First();
                        return;
                    }
                }

                error.FullJson = error.ToJson();

                c.Execute(@"
Insert Into Exceptions (GUID, ApplicationName, MachineName, CreationDate, Type, IsProtected, Host, Url, HTTPMethod, IPAddress, Source, Message, Detail, StatusCode, `SQL`, FullJson, ErrorHash, DuplicateCount)
Values (@GUID, @ApplicationName, @MachineName, @CreationDate, @Type, @IsProtected, @Host, @Url, @HTTPMethod, @IPAddress, @Source, @Message, @Detail, @StatusCode, @SQL, @FullJson, @ErrorHash, @DuplicateCount)",
                            new
                            {
                                error.GUID,
                                ApplicationName = error.ApplicationName.Truncate(50),
                                MachineName = error.MachineName.Truncate(50),
                                error.CreationDate,
                                Type = error.Type.Truncate(100),
                                error.IsProtected,
                                Host = error.Host.Truncate(100),
                                Url = error.Url.Truncate(500),
                                HTTPMethod = error.HTTPMethod.Truncate(10), // this feels silly, but you never know when someone will up and go crazy with HTTP 1.2!
                                error.IPAddress,
                                Source = error.Source.Truncate(100),
                                Message = error.Message.Truncate(1000),
                                error.Detail,
                                error.StatusCode,
                                error.SQL,
                                error.FullJson,
                                error.ErrorHash,
                                error.DuplicateCount
                            });
            }
        }
开发者ID:NickCraver,项目名称:StackExchange.Exceptional,代码行数:67,代码来源:MySQLErrorStore.cs

示例4: LogError

 private void LogError(Error error, StreamWriter outstream)
 {
     var json = error.ToJson();
     outstream.Write(json); //TODO: consider making this async
     outstream.Flush();
 }
开发者ID:hongduo168,项目名称:StackExchange.Exceptional,代码行数:6,代码来源:JSONErrorStore.cs


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