Skip to content

Commit bb71ca5

Browse files
committed
Change nlog and log4net to allow setting the min log level.
1 parent da1f9f3 commit bb71ca5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

Source/Platforms/Log4net/Log4netExceptionlessLog.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,45 @@
44

55
namespace Exceptionless.Log4net {
66
public class Log4netExceptionlessLog : IExceptionlessLog {
7-
// ignore and let NLog determine what should be captured.
7+
public Log4netExceptionlessLog(LogLevel? minimumLogLevel = null) {
8+
if (minimumLogLevel.HasValue)
9+
MinimumLogLevel = minimumLogLevel.Value;
10+
}
11+
812
public LogLevel MinimumLogLevel { get; set; }
913

1014
public void Error(string message, string source = null, Exception exception = null) {
15+
if (LogLevel.Error < MinimumLogLevel)
16+
return;
17+
1118
LogManager.GetLogger(source ?? "Exceptionless").Error(message, exception);
1219
}
1320

1421
public void Info(string message, string source = null) {
22+
if (LogLevel.Info < MinimumLogLevel)
23+
return;
24+
1525
LogManager.GetLogger(source ?? "Exceptionless").Info(message);
1626
}
1727

1828
public void Debug(string message, string source = null) {
29+
if (LogLevel.Debug < MinimumLogLevel)
30+
return;
31+
1932
LogManager.GetLogger(source ?? "Exceptionless").Debug(message);
2033
}
2134

2235
public void Warn(string message, string source = null) {
36+
if (LogLevel.Warn < MinimumLogLevel)
37+
return;
38+
2339
LogManager.GetLogger(source ?? "Exceptionless").Warn(message);
2440
}
2541

2642
public void Trace(string message, string source = null) {
43+
if (LogLevel.Trace < MinimumLogLevel)
44+
return;
45+
2746
LogManager.GetLogger(source ?? "Exceptionless").Debug(message);
2847
}
2948

Source/Platforms/NLog/NLogExceptionlessLog.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,45 @@
44

55
namespace Exceptionless.NLog {
66
public class NLogExceptionlessLog : IExceptionlessLog {
7-
// ignore and let NLog determine what should be captured.
7+
public NLogExceptionlessLog(LogLevel? minimumLogLevel = null) {
8+
if (minimumLogLevel.HasValue)
9+
MinimumLogLevel = minimumLogLevel.Value;
10+
}
11+
812
public LogLevel MinimumLogLevel { get; set; }
913

1014
public void Error(string message, string source = null, Exception exception = null) {
15+
if (LogLevel.Error < MinimumLogLevel)
16+
return;
17+
1118
Log.Error().Message(message).LoggerName(source).Exception(exception).Write();
1219
}
1320

1421
public void Info(string message, string source = null) {
22+
if (LogLevel.Info < MinimumLogLevel)
23+
return;
24+
1525
Log.Info().Message(message).LoggerName(source).Write();
1626
}
1727

1828
public void Debug(string message, string source = null) {
29+
if (LogLevel.Debug < MinimumLogLevel)
30+
return;
31+
1932
Log.Debug().Message(message).LoggerName(source).Write();
2033
}
2134

2235
public void Warn(string message, string source = null) {
36+
if (LogLevel.Warn < MinimumLogLevel)
37+
return;
38+
2339
Log.Warn().Message(message).LoggerName(source).Write();
2440
}
2541

2642
public void Trace(string message, string source = null) {
43+
if (LogLevel.Trace < MinimumLogLevel)
44+
return;
45+
2746
Log.Trace().Message(message).LoggerName(source).Write();
2847
}
2948

0 commit comments

Comments
 (0)