7

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

1 Answer 1

15
  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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.