Skip to content

Commit

Permalink
Support for specifying API key and log ID in appsettings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Jun 20, 2018
1 parent 1990e15 commit 8b3af11
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion samples/Elmah.Io.Extensions.Logging.AspNetCore2/Program.cs
@@ -1,6 +1,7 @@
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Elmah.Io.Extensions.Logging.AspNetCore2
Expand All @@ -17,8 +18,15 @@ public static void Main(string[] args)
.UseStartup<Startup>()
.ConfigureLogging((ctx, logging) =>
{
// Use the following line to configure the elmah.io provider from appsettings
// Use the following to configure API key and log ID in appsettings.json
//logging.Services.Configure<ElmahIoProviderOptions>(ctx.Configuration.GetSection("ElmahIo"));
// Use the following line to configure elmah.io provider settings like log level from appsettings.json
//logging.AddConfiguration(ctx.Configuration.GetSection("Logging"));
// If everything is configured in appsettings.json, call the AddElmahIo overload without an options action
//logging.AddElmahIo();
logging
.AddElmahIo(options =>
{
Expand All @@ -30,6 +38,7 @@ public static void Main(string[] args)
// msg.Version = "2.0.0";
//};
});
// The elmah.io provider can log any log level, but we recommend only to log warning and up
logging.AddFilter<ElmahIoLoggerProvider>(null, LogLevel.Warning);
})
Expand Down
Expand Up @@ -2,11 +2,15 @@
"Logging": {
"IncludeScopes": false,
// elmah.io provider can be configured through appsettings as well

"ElmahIo": {
"LogLevel": {
"Default": "Warning"
}
}
},
// elmah.io API key and log ID can be configured here if you don't want it in C#
"ElmahIo": {
"ApiKey": "API_KEY",
"LogId": "LOG_ID"
}
}
Expand Up @@ -10,10 +10,16 @@ public static class ElmahIoLoggingBuilderExtensions
{
public static ILoggingBuilder AddElmahIo(this ILoggingBuilder builder, Action<ElmahIoProviderOptions> configure)
{
builder.Services.AddSingleton<ILoggerProvider, ElmahIoLoggerProvider>();
builder.AddElmahIo();
builder.Services.Configure(configure);
return builder;
}

public static ILoggingBuilder AddElmahIo(this ILoggingBuilder builder)
{
builder.Services.AddSingleton<ILoggerProvider, ElmahIoLoggerProvider>();
return builder;
}
}
}

Expand Down

0 comments on commit 8b3af11

Please sign in to comment.