Skip to content

Commit 580eea7

Browse files
committed
#Fix 260, Add minimum log fixes for Microsoft.Extensions.Logging, Log4net
I also fixed the case for set default min log level on NLog when using the default client.
1 parent 941e983 commit 580eea7

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

src/Platforms/Exceptionless.Extensions.Logging/ExceptionlessLoggerExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static ILoggingBuilder AddExceptionless(this ILoggingBuilder builder, Act
8989
/// <param name="factory">The <see cref="ILoggerFactory"/>.</param>
9090
/// <param name="client">If a client is not specified then the <see cref="ExceptionlessClient.Default"/> will be used.</param>
9191
/// <returns>The <see cref="ILoggerFactory"/>.</returns>
92-
[Obsolete("Use ExceptionlessLoggerExtensions.AddExceptionless(ILoggingBuilder,ExceptionlessClient) instead.")]
92+
[Obsolete("Use ExceptionlessLoggerExtensions.AddExceptionless(ILoggingBuilder, ExceptionlessClient) instead.")]
9393
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, ExceptionlessClient client = null) {
9494
factory.AddProvider(new ExceptionlessLoggerProvider(client ?? ExceptionlessClient.Default));
9595
return factory;
@@ -102,7 +102,7 @@ public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, Excep
102102
/// <param name="apiKey">The project api key.</param>
103103
/// <param name="serverUrl">The Server Url</param>
104104
/// <returns>The <see cref="ILoggerFactory"/>.</returns>
105-
[Obsolete("Use ExceptionlessLoggerExtensions.AddExceptionless(ILoggingBuilder,string,string) instead.")]
105+
[Obsolete("Use ExceptionlessLoggerExtensions.AddExceptionless(ILoggingBuilder, string, string) instead.")]
106106
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, string apiKey, string serverUrl = null) {
107107
if (String.IsNullOrEmpty(apiKey) && String.IsNullOrEmpty(serverUrl))
108108
return factory.AddExceptionless();
@@ -125,7 +125,7 @@ public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, strin
125125
/// <param name="factory">The <see cref="ILoggerFactory"/>.</param>
126126
/// <param name="configure">An <see cref="Action{ExceptionlessConfiguration}"/> that applies additional settings and plugins. The project api key must be specified.</param>
127127
/// <returns>The <see cref="ILoggerFactory"/>.</returns>
128-
[Obsolete("Use ExceptionlessLoggerExtensions.AddExceptionless(ILoggingBuilder,Action<ExceptionlessConfiguration>) instead.")]
128+
[Obsolete("Use ExceptionlessLoggerExtensions.AddExceptionless(ILoggingBuilder, Action<ExceptionlessConfiguration>) instead.")]
129129
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, Action<ExceptionlessConfiguration> configure) {
130130
factory.AddProvider(new ExceptionlessLoggerProvider(configure));
131131
return factory;

src/Platforms/Exceptionless.Extensions.Logging/ExceptionlessLoggerProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ public class ExceptionlessLoggerProvider : ILoggerProvider {
1111
/// </summary>
1212
public ExceptionlessLoggerProvider(ExceptionlessClient client) {
1313
_client = client ?? throw new ArgumentNullException(nameof(client));
14+
15+
// Rely on Logging Rules
16+
_client.Configuration.SetDefaultMinLogLevel(Exceptionless.Logging.LogLevel.Trace);
1417
}
1518

1619
/// <summary>
1720
/// Initializes a new instance of the <see cref="ExceptionlessLoggerProvider"/> class.
1821
/// </summary>
1922
/// <param name="configure">An <see cref="Action{ExceptionlessConfiguration}"/> which will be used to configure created loggers.</param>
2023
public ExceptionlessLoggerProvider(Action<ExceptionlessConfiguration> configure) {
21-
configure?.Invoke(ExceptionlessClient.Default.Configuration);
2224
_client = ExceptionlessClient.Default;
25+
26+
// Rely on Logging Rules
27+
_client.Configuration.SetDefaultMinLogLevel(Exceptionless.Logging.LogLevel.Trace);
28+
29+
configure?.Invoke(_client.Configuration);
2330
_shouldDispose = true;
2431
}
2532

src/Platforms/Exceptionless.Log4net/BufferingExceptionlessAppender.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public override void ActivateOptions() {
2525
config.ApiKey = ApiKey;
2626
if (!String.IsNullOrEmpty(ServerUrl))
2727
config.ServerUrl = ServerUrl;
28+
2829
config.UseInMemoryStorage();
30+
31+
// Rely on Logging Rules
32+
config.SetDefaultMinLogLevel(Logging.LogLevel.Trace);
2933
});
3034
}
3135

src/Platforms/Exceptionless.Log4net/ExceptionlessAppender.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public override void ActivateOptions() {
1818
config.ApiKey = ApiKey;
1919
if (!String.IsNullOrEmpty(ServerUrl))
2020
config.ServerUrl = ServerUrl;
21+
2122
config.UseInMemoryStorage();
23+
24+
// Rely on Logging Rules
25+
config.SetDefaultMinLogLevel(Logging.LogLevel.Trace);
2226
});
2327
}
2428

src/Platforms/Exceptionless.Log4net/ExceptionlessClientExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, L
2020
builder.SetSource(ev.LoggerName);
2121

2222
var props = ev.GetProperties();
23-
foreach (var key in props.GetKeys().Where(key => !_ignoredEventProperties.Contains(key, StringComparer.OrdinalIgnoreCase))) {
23+
foreach (string key in props.GetKeys().Where(key => !_ignoredEventProperties.Contains(key, StringComparer.OrdinalIgnoreCase))) {
2424
string propName = key;
2525
if (propName.StartsWith("log4net:"))
2626
propName = propName.Substring(8);

src/Platforms/Exceptionless.NLog/ExceptionlessTarget.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,26 @@ public ExceptionlessTarget() {
2828
protected override void InitializeTarget() {
2929
base.InitializeTarget();
3030

31-
var apiKey = RenderLogEvent(ApiKey, LogEventInfo.CreateNullEvent());
32-
var serverUrl = RenderLogEvent(ServerUrl, LogEventInfo.CreateNullEvent());
31+
string apiKey = RenderLogEvent(ApiKey, LogEventInfo.CreateNullEvent());
32+
string serverUrl = RenderLogEvent(ServerUrl, LogEventInfo.CreateNullEvent());
3333

3434
if (!String.IsNullOrEmpty(apiKey) || !String.IsNullOrEmpty(serverUrl)) {
3535
_client = new ExceptionlessClient(config => {
3636
if (!String.IsNullOrEmpty(apiKey) && apiKey != "API_KEY_HERE")
3737
config.ApiKey = apiKey;
3838
if (!String.IsNullOrEmpty(serverUrl))
3939
config.ServerUrl = serverUrl;
40+
4041
config.UseLogger(new NLogInternalLoggger());
4142
config.UseInMemoryStorage();
42-
config.SetDefaultMinLogLevel(Logging.LogLevel.Trace); // Rely on NLog Logging Rules
43+
44+
// Rely on Logging Rules
45+
config.SetDefaultMinLogLevel(Logging.LogLevel.Trace);
4346
});
44-
}
45-
else {
47+
} else {
48+
// Rely on Logging Rules
49+
_client.Configuration.SetDefaultMinLogLevel(Logging.LogLevel.Trace);
50+
4651
if (_client.Configuration.Resolver.HasDefaultRegistration<Logging.IExceptionlessLog, Logging.NullExceptionlessLog>()) {
4752
_client.Configuration.UseLogger(new NLogInternalLoggger());
4853
}

0 commit comments

Comments
 (0)