Mukil Deepthi
Mukil Deepthi

Reputation: 6452

ASP.Net Core 2.0 Webapi set log4net

I am new to asp.net core 2.0. I creating a webapi and want to configure log4net as my logging provider.

I couldn't find some working example in net. Can anyone help me provide the right link or some sample code about how to properly setup log4net in asp.net core 2.0

Things i have done so far is as below and i am not sure how to proceed further.

installed log4net.Extensions.AspNetCore;

Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    loggerFactory.AddLog4Net();

    // Enable CORS 
    app.UseCors(builder => builder.AllowAnyOrigin()
        .AllowAnyMethod()
        .AllowAnyHeader()
        .AllowCredentials());

    app.UseMvc();
}

Upvotes: 7

Views: 13112

Answers (1)

aksu
aksu

Reputation: 1847

  1. Install nuget for Microsoft.Extensions.Logging.Log4Net.AspNetCore (https://www.nuget.org/packages/Microsoft.Extensions.Logging.Log4Net.AspNetCore/)
  2. In Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) call loggerFactory.AddLog4Net();
  3. Create log4net.config

More info -> https://github.com/huorswords/Microsoft.Extensions.Logging.Log4Net.AspNetCore

Upvotes: 15

Related Questions