Skip to content

Commit 55ff465

Browse files
committed
Add ability to configure default client through lambda in UseExceptionless method. Fix some null references.
1 parent 6efb9c6 commit 55ff465

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

samples/Exceptionless.SampleAspNetCore/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public void ConfigureServices(IServiceCollection services) {
3131
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) {
3232
app.UseExceptionless(Configuration);
3333
//OR
34-
//app.UseExceptionless(new ExceptionlessClient(c => c.ReadFromConfiguration(Configuration)));
34+
//app.UseExceptionless(c => c.ReadFromConfiguration(Configuration));
3535
//OR
3636
//app.UseExceptionless("API_KEY_HERE");
3737
//OR
3838
//loggerFactory.AddExceptionless("API_KEY_HERE");
3939
//OR
40-
//loggerFactory.AddExceptionless((c) => c.ReadFromConfiguration(Configuration));
40+
//loggerFactory.AddExceptionless(c => c.ReadFromConfiguration(Configuration));
4141

4242
//loggerFactory.AddExceptionless();
4343
app.UseRouting();

src/Exceptionless/Extensions/ExceptionlessClientExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Exceptionless.Plugins;
66
using Exceptionless.Logging;
77
using Exceptionless.Models;
8-
using Exceptionless.Services;
9-
using Exceptionless.Submission;
108

119
namespace Exceptionless {
1210
public static class ExceptionlessClientExtensions {

src/Exceptionless/Plugins/Default/080_VersionPlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ private Assembly GetEntryAssembly(IExceptionlessLog log) {
114114
}
115115

116116
private bool IsUserAssembly(Assembly assembly) {
117+
if (assembly == null)
118+
return false;
119+
117120
if (!String.IsNullOrEmpty(assembly.FullName) && (assembly.FullName.StartsWith("System.") || assembly.FullName.StartsWith("Microsoft.")))
118121
return false;
119122

120-
string company = assembly.GetCompany();
123+
string company = assembly.GetCompany() ?? String.Empty;
121124
string[] nonUserCompanies = new[] { "Exceptionless", "Microsoft" };
122125
if (nonUserCompanies.Any(c => company.IndexOf(c, StringComparison.OrdinalIgnoreCase) >= 0))
123126
return false;

src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Exceptionless {
2020
public static class ExceptionlessExtensions {
2121
public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app, ExceptionlessClient client = null) {
2222
if (client == null)
23-
client = ExceptionlessClient.Default;
23+
client = app.ApplicationServices.GetService<ExceptionlessClient>() ?? ExceptionlessClient.Default;
2424

2525
// Can be registered in Startup.ConfigureServices via services.AddHttpContextAccessor();
2626
// this is necessary to obtain Session and Request information outside of ExceptionlessMiddleware
@@ -40,6 +40,11 @@ public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app,
4040
return app.UseMiddleware<ExceptionlessMiddleware>(client);
4141
}
4242

43+
public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app, Action<ExceptionlessConfiguration> configure) {
44+
configure?.Invoke(ExceptionlessClient.Default.Configuration);
45+
return app.UseExceptionless(ExceptionlessClient.Default);
46+
}
47+
4348
public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app, IConfiguration configuration) {
4449
ExceptionlessClient.Default.Configuration.ReadFromConfiguration(configuration);
4550
return app.UseExceptionless(ExceptionlessClient.Default);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static ExceptionlessLogLevel ToLogLevel(this LogLevel level) {
2323

2424
return ExceptionlessLogLevel.Off;
2525
}
26+
2627
/// <summary>
2728
/// Adds Exceptionless to the logging pipeline using the <see cref="ExceptionlessClient.Default"/>.
2829
/// </summary>
@@ -33,6 +34,7 @@ public static ILoggingBuilder AddExceptionless(this ILoggingBuilder builder, Exc
3334
builder.AddProvider(new ExceptionlessLoggerProvider(client ?? ExceptionlessClient.Default));
3435
return builder;
3536
}
37+
3638
/// <summary>
3739
/// Adds Exceptionless to the logging pipeline using a new client with the provided api key.
3840
/// </summary>
@@ -55,6 +57,7 @@ public static ILoggingBuilder AddExceptionless(this ILoggingBuilder builder, str
5557

5658
return builder;
5759
}
60+
5861
/// <summary>
5962
/// Adds Exceptionless to the logging pipeline using a new client configured with the provided action.
6063
/// </summary>
@@ -65,6 +68,7 @@ public static ILoggingBuilder AddExceptionless(this ILoggingBuilder builder, Act
6568
builder.AddProvider(new ExceptionlessLoggerProvider(configure));
6669
return builder;
6770
}
71+
6872
/// <summary>
6973
/// Adds Exceptionless to the logging pipeline using the <see cref="ExceptionlessClient.Default"/>.
7074
/// </summary>

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ public ExceptionlessLoggerProvider(ExceptionlessClient client) {
1818
/// </summary>
1919
/// <param name="configure">An <see cref="Action{ExceptionlessConfiguration}"/> which will be used to configure created loggers.</param>
2020
public ExceptionlessLoggerProvider(Action<ExceptionlessConfiguration> configure) {
21-
if (configure == null)
22-
throw new ArgumentNullException(nameof(configure));
23-
24-
_client = new ExceptionlessClient(configure);
21+
configure?.Invoke(ExceptionlessClient.Default.Configuration);
22+
_client = ExceptionlessClient.Default;
2523
_shouldDispose = true;
2624
}
2725

0 commit comments

Comments
 (0)