Skip to content

Commit af96f03

Browse files
committed
Added additional constructors and sample ASP.NET Core usage.
1 parent 97ce143 commit af96f03

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

samples/Exceptionless.SampleAspNetCore/Exceptionless.SampleAspNetCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15+
<ProjectReference Include="..\..\src\Exceptionless.Extensions.Logging\Exceptionless.Extensions.Logging.csproj" />
1516
<ProjectReference Include="..\..\src\Exceptionless\Exceptionless.csproj" />
1617
<ProjectReference Include="..\..\src\Platforms\Exceptionless.AspNetCore\Exceptionless.AspNetCore.csproj" />
1718
</ItemGroup>

samples/Exceptionless.SampleAspNetCore/Startup.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Extensions.DependencyInjection;
66
using Microsoft.Extensions.Logging;
7-
using Exceptionless;
87

98
namespace Exceptionless.SampleAspNetCore {
109
public class Startup {
@@ -24,10 +23,14 @@ public void ConfigureServices(IServiceCollection services) {
2423

2524
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
2625
app.UseExceptionless(Configuration);
27-
// OR
26+
//OR
2827
//app.UseExceptionless(new ExceptionlessClient(c => c.ReadFromConfiguration(Configuration)));
29-
// OR
28+
//OR
3029
//app.UseExceptionless("API_KEY_HERE");
30+
//OR
31+
//loggerFactory.AddExceptionless("API_KEY_HERE");
32+
//OR
33+
//loggerFactory.AddExceptionless((c) => c.ReadFromConfiguration(Configuration));
3134

3235
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
3336
loggerFactory.AddDebug();

src/Exceptionless.Extensions.Logging/ExceptionlessLoggerExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,17 @@ public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, Excep
3232
factory.AddProvider(new ExceptionlessLoggerProvider(config));
3333
return factory;
3434
}
35+
36+
/// <summary>
37+
/// Adds Exceptionless to the logging pipeline.
38+
/// </summary>
39+
/// <param name="factory">The <see cref="ILoggerFactory"/>.</param>
40+
/// <param name="configure">An <see cref="Action{ExceptionlessConfiguration}"/> that applies additional settings and plugins. The project api key must be specified.</param>
41+
/// <returns>The <see cref="ILoggerFactory"/>.</returns>
42+
public static ILoggerFactory AddExceptionless(this ILoggerFactory factory, Action<ExceptionlessConfiguration> configure)
43+
{
44+
factory.AddProvider(new ExceptionlessLoggerProvider(configure));
45+
return factory;
46+
}
3547
}
3648
}

src/Exceptionless.Extensions.Logging/ExceptionlessLoggerProvider.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public ExceptionlessLoggerProvider(ExceptionlessConfiguration config)
2020
_Client.Startup();
2121
}
2222

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="ExceptionlessLoggerProvider"/> class.
25+
/// </summary>
26+
/// <param name="configure">An <see cref="Action{ExceptionlessConfiguration}"/> which will be used to configure created loggers.</param>
27+
public ExceptionlessLoggerProvider(Action<ExceptionlessConfiguration> configure) {
28+
if (configure == null)
29+
throw new ArgumentNullException(nameof(configure));
30+
31+
_Client = new ExceptionlessClient(configure);
32+
_Client.Startup();
33+
}
34+
2335
/// <summary>
2436
/// Creates a new <see cref="ILogger"/> instance.
2537
/// </summary>
@@ -33,6 +45,7 @@ public ILogger CreateLogger(string categoryName)
3345
public void Dispose()
3446
{
3547
_Client.Shutdown();
48+
((IDisposable)_Client).Dispose();
3649
}
3750
}
3851
}

0 commit comments

Comments
 (0)