ElmahCore not creating xml log files
Please help. ElmahCore not creating xml log files. I tried the given code in documentation but not working. and i can't find any solution on internet and given project ElmahCore.Demo
I tried below code in ConfigureServices of Startup.cs
services.AddElmah<XmlFileErrorLog>(options =>
{
options.LogPath = "~/Helpers/log";
});
services.AddElmah<XmlFileErrorLog>(options =>
{
options.LogPath = "~/Helpers/log";
});
and
app.UseElmah(); in Configure
i have written all code as given in this documentation but not working
This code works for me:
services.AddElmah<XmlFileErrorLog>(options =>
{
options.LogPath = "~/logs";
});
Send more info or project.
I'm using this code in Startup.cs It is not throwing any exception and not creating log files to given path but saving errors to SQL Server
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
-- I'm using version core 2.2
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddAutoMapper();
var appSettingsSection = Configuration.GetSection("AppSettings");
services.Configure<AppSettings>(appSettingsSection);
var appSettings = appSettingsSection.Get<AppSettings>();
var key = Encoding.ASCII.GetBytes(appSettings.Secret);
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false
};
});
services.AddElmah<XmlFileErrorLog>(options =>
{
options.LogPath = "~/Helpers/log";
});
services.AddElmah<SqlErrorLog>(options =>
{
options.ConnectionString = @"Data Source=IJAZ-PC;Initial Catalog=faastrak-01-mar-2019;Integrated Security=True";
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc();
app.UseElmah();
}
app.UseElmah() must be after initializing other exception handling middleware, such as (UseExceptionHandler, UseDeveloperExceptionPage, etc.)
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseAuthentication();
app.UseElmah(); //moved
app.UseHttpsRedirection();
app.UseMvc();
still not working!
Multiple ErrorLog's not supported yet :(
services.AddElmah<XmlFileErrorLog>
...
services.AddElmah<SqlErrorLog>
Will work last added ErrorLog (services.AddElmah<SqlErrorLog>).
I’ll close this in the next release.
OK thanks in Advance
Nope, not working for me either. Nothing logged. Simple steps, correct order, not working.
Ok, it is logging now. Apparently it's very picky about where you put the UseElmah() line.