From 3b87db2e03c7c4c2e85e19f435c68c088658e1cf Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Fri, 2 Feb 2018 18:37:18 +0100 Subject: [PATCH] EXPERIMENTAL: log a message about discarded email notifications. Refers to #4 --- ATxCommon/NLog/RateLimitWrapper.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ATxCommon/NLog/RateLimitWrapper.cs b/ATxCommon/NLog/RateLimitWrapper.cs index 2170a48..72caf79 100644 --- a/ATxCommon/NLog/RateLimitWrapper.cs +++ b/ATxCommon/NLog/RateLimitWrapper.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using NLog; using NLog.Common; using NLog.Targets; using NLog.Targets.Wrappers; @@ -18,6 +19,7 @@ namespace ATxCommon.NLog public class RateLimitWrapper : WrapperTargetBase { private DateTime _lastLogEvent = DateTime.MinValue; + private static readonly Logger Log = LogManager.GetCurrentClassLogger(); protected override void Write(AsyncLogEventInfo logEvent) { if ((DateTime.Now - _lastLogEvent).TotalMinutes >= MinLogInterval) { @@ -25,6 +27,11 @@ namespace ATxCommon.NLog WrappedTarget.WriteAsyncLogEvent(logEvent); } else { logEvent.Continuation(null); + // EXPERIMENTAL: check if the level of the log event is higher than "WARN" (3) and + // log a debug message about keeping back the email message: + if (logEvent.LogEvent.Level.Ordinal > 3) { + Log.Debug("RateLimitWrapper: not sending email, frequency too high!"); + } } } -- GitLab