Skip to content

Commit b59eb4d

Browse files
committed
Added internal logging implementation for Microsoft.Extensions.Logging.
1 parent 13ee3ab commit b59eb4d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using Exceptionless.Logging;
3+
using Microsoft.Extensions.Logging;
4+
using LogLevel = Exceptionless.Logging.LogLevel;
5+
6+
namespace Exceptionless.Extensions.Logging {
7+
public class ExtensionsExceptionlessLog : IExceptionlessLog {
8+
private readonly ILoggerFactory _loggerFactory;
9+
10+
public ExtensionsExceptionlessLog(ILoggerFactory loggerFactory, LogLevel minimumLogLevel = null) {
11+
_loggerFactory = loggerFactory;
12+
if (minimumLogLevel != null)
13+
MinimumLogLevel = minimumLogLevel;
14+
}
15+
16+
public LogLevel MinimumLogLevel { get; set; }
17+
18+
public void Error(string message, string source = null, Exception exception = null) {
19+
if (LogLevel.Error < MinimumLogLevel)
20+
return;
21+
22+
GetLogger(source).LogError(exception, message);
23+
}
24+
25+
public void Info(string message, string source = null) {
26+
if (LogLevel.Info < MinimumLogLevel)
27+
return;
28+
29+
GetLogger(source).LogInformation(message);
30+
}
31+
32+
public void Debug(string message, string source = null) {
33+
if (LogLevel.Debug < MinimumLogLevel)
34+
return;
35+
36+
GetLogger(source).LogDebug(message);
37+
}
38+
39+
public void Warn(string message, string source = null) {
40+
if (LogLevel.Warn < MinimumLogLevel)
41+
return;
42+
43+
GetLogger(source).LogWarning(message);
44+
}
45+
46+
public void Trace(string message, string source = null) {
47+
if (LogLevel.Trace < MinimumLogLevel)
48+
return;
49+
50+
GetLogger(source).LogDebug(message);
51+
}
52+
53+
private ILogger GetLogger(string source) {
54+
return _loggerFactory.CreateLogger(source ?? "Exceptionless");
55+
}
56+
57+
public void Flush() { }
58+
}
59+
}

0 commit comments

Comments
 (0)