ElmahCore icon indicating copy to clipboard operation
ElmahCore copied to clipboard

ElmahCore not creating xml log files

Open itbeam opened this issue 7 years ago • 11 comments

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";

        });

itbeam avatar Apr 03 '19 13:04 itbeam

services.AddElmah<XmlFileErrorLog>(options =>
{
    options.LogPath = "~/Helpers/log";
});

and

app.UseElmah(); in Configure

ElmahCore avatar Apr 03 '19 13:04 ElmahCore

i have written all code as given in this documentation but not working

itbeam avatar Apr 03 '19 13:04 itbeam

This code works for me:

services.AddElmah<XmlFileErrorLog>(options =>
 {
       options.LogPath = "~/logs";
});

Send more info or project.

ElmahCore avatar Apr 03 '19 14:04 ElmahCore

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();
    }

itbeam avatar Apr 03 '19 14:04 itbeam

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();

ElmahCore avatar Apr 03 '19 14:04 ElmahCore

still not working!

itbeam avatar Apr 03 '19 14:04 itbeam

Multiple ErrorLog's not supported yet :(

services.AddElmah<XmlFileErrorLog>
...
services.AddElmah<SqlErrorLog>

Will work last added ErrorLog (services.AddElmah<SqlErrorLog>).

ElmahCore avatar Apr 03 '19 15:04 ElmahCore

I’ll close this in the next release.

ElmahCore avatar Apr 03 '19 15:04 ElmahCore

OK thanks in Advance

itbeam avatar Apr 04 '19 07:04 itbeam

Nope, not working for me either. Nothing logged. Simple steps, correct order, not working.

brgrz avatar Aug 09 '19 11:08 brgrz

Ok, it is logging now. Apparently it's very picky about where you put the UseElmah() line.

brgrz avatar Aug 09 '19 11:08 brgrz