I am trying to configure elmah with sql server. The configuration I see are of this form
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
...
}
private static void InjectsAuthElements(IServiceCollection services)
{
...
services.AddElmah<SqlErrorLog>(options =>
{
options.Path = "ElmahNewNameForSecurity.axd";
options.OnPermissionCheck = context => context.User.Identity.IsAuthenticated && context.User.IsInRole("Admin");
options.ConnectionString = "MyConnectionString";
});
}
}
I want to replace MyConnectionString by something like Configuration.GetConnectionString("Default")
.
Just add an IConfiguration
interface as a second parameter to the method and pass the Configuration
when you call the method.
private static void InjectsAuthElements(
IServiceCollection services,
IConfiguration configuration)
{
...
services.AddElmah<SqlErrorLog>(options =>
{
options.Path = "ElmahNewNameForSecurity.axd";
options.OnPermissionCheck = context => context.User.Identity.IsAuthenticated && context.User.IsInRole("Admin");
options.ConnectionString = "MyConnectionString";
});
}