Asp net core 2 2 iis where can I see logs ilogger for my app in iis on serv

Introduction to ASP.NET

ASP.NET is a popular programming language used for web applications. It provides a for developing dynamic websites, web services, and web APIs. ASP.NET is a part of the .NET and is widely used by developers around the world.

ASP.NET Core 2.2

ASP.NET Core 2.2 is the latest version of ASP.NET Core, which is an open-, cross-platform framework for building modern web applications. It provides a high-, scalable, and modular architecture for developing web applications.

in ASP.NET Core 2.2

Logging is an essential part of any application as it helps in troubleshooting and monitoring the application's behavior. In ASP.NET Core 2.2, logging is done using the ILogger interface, which is a part of the Microsoft.Extensions.Logging namespace.

Viewing Logs in IIS

If you are hosting your ASP.NET Core 2.2 application on IIS (Internet Information Services), you might wonder you can see the logs generated by your application. By default, the logs are not visible in the IIS logs folder.

To view the logs for your ASP.NET Core 2.2 application in IIS, you need to configure the logging provider in your application's startup code. Here's an example of how you can configure the logging provider to write logs to a file:


public  Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // Configure other services
        services.AddLogging(logging =>
        {
            logging.();
            logging.AddFile("logs/myapp-{Date}.txt");
        });
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        // Configure other middleware
        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

In the above example, we are using the AddFile extension method to configure the logging provider to write logs to a file. The logs will be stored in the “logs” folder with a filename that includes the current date.

Accessing Logs in IIS

Once you have configured the logging provider, you can access the logs generated by your ASP.NET Core 2.2 application in IIS. The logs will be stored in the specified file location.

To access the logs, you can navigate to the file location using the file explorer on your server. Alternatively, you can use a tool like Log Parser Studio to query and analyze the logs.

By following the above steps, you can easily view and access the logs for your ASP.NET Core 2.2 application hosted on IIS. Logging is an aspect of application development, and ASP.NET Core provides a flexible and powerful logging framework to meet your application's logging needs.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents