コード例 #1
0
        void LogWithThrottling(Exception ex)
        {
            var hash = ex.ToString();
            ErrorThrottlingContext ctx;

            if (!loggedError.TryGetValue(hash, out ctx))
            {
                ctx = new ErrorThrottlingContext {
                    RaisedAt = DateTime.UtcNow, Times = 1
                };
                loggedError[hash] = ctx;
                log.Error(ex);
            }
            else
            {
                ctx.Times++;
            }

            if (DateTime.UtcNow - ctx.RaisedAt > TimeSpan.FromSeconds(10))
            {
                ctx.RaisedAt = DateTime.UtcNow;
                log.Error(new Exception(string.Format("Repeated {0} times", ctx.Times), ex));
            }
        }
コード例 #2
0
        void LogWithThrottling(Exception ex)
        {
            var hash = ex.ToString();
            ErrorThrottlingContext ctx;
            if (!loggedError.TryGetValue(hash, out ctx))
            {
                ctx = new ErrorThrottlingContext { RaisedAt = DateTime.UtcNow, Times = 1 };
                loggedError[hash] = ctx;
                log.Error(ex);
            }
            else
            {
                ctx.Times++;
            }

            if (DateTime.UtcNow - ctx.RaisedAt > TimeSpan.FromSeconds(10))
            {
                ctx.RaisedAt = DateTime.UtcNow;
                log.Error(new Exception(string.Format("Repeated {0} times", ctx.Times), ex));
            }
        }