Skip to content
Snippets Groups Projects
Commit 3b87db2e authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

EXPERIMENTAL: log a message about discarded email notifications.

Refers to #4
parent 497e0b3b
No related branches found
No related tags found
No related merge requests found
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using NLog;
using NLog.Common; using NLog.Common;
using NLog.Targets; using NLog.Targets;
using NLog.Targets.Wrappers; using NLog.Targets.Wrappers;
...@@ -18,6 +19,7 @@ namespace ATxCommon.NLog ...@@ -18,6 +19,7 @@ namespace ATxCommon.NLog
public class RateLimitWrapper : WrapperTargetBase public class RateLimitWrapper : WrapperTargetBase
{ {
private DateTime _lastLogEvent = DateTime.MinValue; private DateTime _lastLogEvent = DateTime.MinValue;
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
protected override void Write(AsyncLogEventInfo logEvent) { protected override void Write(AsyncLogEventInfo logEvent) {
if ((DateTime.Now - _lastLogEvent).TotalMinutes >= MinLogInterval) { if ((DateTime.Now - _lastLogEvent).TotalMinutes >= MinLogInterval) {
...@@ -25,6 +27,11 @@ namespace ATxCommon.NLog ...@@ -25,6 +27,11 @@ namespace ATxCommon.NLog
WrappedTarget.WriteAsyncLogEvent(logEvent); WrappedTarget.WriteAsyncLogEvent(logEvent);
} else { } else {
logEvent.Continuation(null); 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!");
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment