Skip to content

Commit fc8238c

Browse files
committed
Added support for ignoring custom log levels
1 parent 73fa9de commit fc8238c

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Source/Shared/Logging/LogLevel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Exceptionless.Logging {
44
public sealed class LogLevel : IComparable, IEquatable<LogLevel> {
5+
public static readonly LogLevel Other = new LogLevel("Other", -1);
56
public static readonly LogLevel Trace = new LogLevel("Trace", 0);
67
public static readonly LogLevel Debug = new LogLevel("Debug", 1);
78
public static readonly LogLevel Info = new LogLevel("Info", 2);
@@ -90,6 +91,8 @@ public int Ordinal {
9091

9192
public static LogLevel FromOrdinal(int ordinal) {
9293
switch (ordinal) {
94+
case -1:
95+
return Other;
9396
case 0:
9497
return Trace;
9598
case 1:
@@ -127,7 +130,7 @@ public static LogLevel FromString(string levelName) {
127130
if (levelName.Equals("Off", StringComparison.OrdinalIgnoreCase))
128131
return LogLevel.Off;
129132

130-
throw new ArgumentException("Unknown log level: " + levelName);
133+
return LogLevel.Other;
131134
}
132135

133136
public override string ToString() {

Source/Shared/Plugins/Default/010_EventExclusionPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void Run(EventPluginContext context) {
2222
var minLogLevel = context.Client.Configuration.Settings.GetMinLogLevel(context.Event.Source);
2323
var logLevel = LogLevel.FromString(context.Event.Data.GetValueOrDefault(Event.KnownDataKeys.Level, "Trace").ToString());
2424

25-
if (logLevel < minLogLevel) {
25+
if (logLevel != LogLevel.Other && (logLevel == LogLevel.Off || logLevel < minLogLevel)) {
2626
context.Log.Info("Cancelling log event due to minimum log level.");
2727
context.Cancel = true;
2828
}

Source/Tests/Plugins/PluginTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public void EventExclusionPlugin_EventExclusions() {
144144
[InlineData(null, null, null, null, false)]
145145
[InlineData("Test", null, null, null, false)]
146146
[InlineData("Test", "Trace", null, null, false)]
147+
[InlineData("Test", "Off", null, null, true)]
148+
[InlineData("Test", "Abc", null, null, false)]
147149
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "Debug", true)]
148150
[InlineData("Test", "Info", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "Debug", false)]
149151
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "*", "Debug", true)]

0 commit comments

Comments
 (0)