Skip to content

Commit 96f5f92

Browse files
committed
Tweaked factory extensions.
1 parent af96f03 commit 96f5f92

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/Exceptionless.Extensions.Logging/ExceptionlessLoggerExtensions.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,29 @@ namespace Exceptionless
77
public static class ExceptionlessLoggerExtensions
88
{
99
/// <summary>
10-
/// Adds Exceptionless to the logging pipeline.
10+
/// Adds Exceptionless to the logging pipeline using the default client.
1111
/// </summary>
1212
/// <param name="factory">The <see cref="ILoggerFactory"/>.</param>
13-
/// <param name="apiKey">The project api key.</param>
1413
/// <returns>The <see cref="ILoggerFactory"/>.</returns>
15-
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, string apiKey)
16-
{
17-
ExceptionlessConfiguration config = new ExceptionlessConfiguration(ExceptionlessClient.Default.Configuration.Resolver);
18-
config.ApiKey = apiKey;
19-
20-
factory.AddProvider(new ExceptionlessLoggerProvider(config));
14+
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory) {
15+
factory.AddProvider(new ExceptionlessLoggerProvider(ExceptionlessClient.Default));
2116
return factory;
2217
}
2318

2419
/// <summary>
25-
/// Adds Exceptionless to the logging pipeline.
20+
/// Adds Exceptionless to the logging pipeline using a new client with the provided api key.
2621
/// </summary>
2722
/// <param name="factory">The <see cref="ILoggerFactory"/>.</param>
28-
/// <param name="config">An <see cref="ExceptionlessConfiguration"/> containing additional settings and plugins. The project api key must be specified.</param>
23+
/// <param name="apiKey">The project api key.</param>
2924
/// <returns>The <see cref="ILoggerFactory"/>.</returns>
30-
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, ExceptionlessConfiguration config)
25+
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, string apiKey)
3126
{
32-
factory.AddProvider(new ExceptionlessLoggerProvider(config));
27+
factory.AddProvider(new ExceptionlessLoggerProvider((config) => config.ApiKey = apiKey));
3328
return factory;
3429
}
3530

3631
/// <summary>
37-
/// Adds Exceptionless to the logging pipeline.
32+
/// Adds Exceptionless to the logging pipeline using a new client configured with the provided action.
3833
/// </summary>
3934
/// <param name="factory">The <see cref="ILoggerFactory"/>.</param>
4035
/// <param name="configure">An <see cref="Action{ExceptionlessConfiguration}"/> that applies additional settings and plugins. The project api key must be specified.</param>

src/Exceptionless.Extensions.Logging/ExceptionlessLoggerProvider.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ namespace Exceptionless.Extensions.Logging
66
public class ExceptionlessLoggerProvider : ILoggerProvider
77
{
88
ExceptionlessClient _Client;
9+
bool _ShouldDisposeClient;
910

1011
/// <summary>
1112
/// Initializes a new instance of the <see cref="ExceptionlessLoggerProvider"/> class.
1213
/// </summary>
1314
/// <param name="config">An <see cref="ExceptionlessConfiguration"/> which will be provided to created loggers.</param>
14-
public ExceptionlessLoggerProvider(ExceptionlessConfiguration config)
15-
{
16-
if (config == null)
17-
throw new ArgumentNullException(nameof(config));
15+
public ExceptionlessLoggerProvider(ExceptionlessClient client) {
16+
if (client == null)
17+
throw new ArgumentNullException(nameof(client));
1818

19-
_Client = new ExceptionlessClient(config);
20-
_Client.Startup();
19+
_Client = client;
20+
_ShouldDisposeClient = false;
2121
}
2222

2323
/// <summary>
@@ -30,6 +30,7 @@ public ExceptionlessLoggerProvider(Action<ExceptionlessConfiguration> configure)
3030

3131
_Client = new ExceptionlessClient(configure);
3232
_Client.Startup();
33+
_ShouldDisposeClient = true;
3334
}
3435

3536
/// <summary>
@@ -44,8 +45,12 @@ public ILogger CreateLogger(string categoryName)
4445

4546
public void Dispose()
4647
{
47-
_Client.Shutdown();
48-
((IDisposable)_Client).Dispose();
48+
_Client.ProcessQueue();
49+
if (_ShouldDisposeClient)
50+
{
51+
_Client.Shutdown();
52+
((IDisposable)_Client).Dispose();
53+
}
4954
}
5055
}
5156
}

0 commit comments

Comments
 (0)