ILogger Asp.net Core not logging Log Level "Information" on IIS 8

1.3k Views Asked by At

I have deployed an Asp.net Core 2 Web application on Windows Server 2012 using IIS 8.

I am not able to log "information" to the Log file, it only logs "Warnings". I have created a custom logger following this link:

https://www.infoworld.com/article/3235249/application-development/how-to-work-with-logging-in-aspnet-core.html

It does the intended job on when deployed on my localhost. I have also enabled the permission hence there is some logging does work such as stdout logs.

However, for recording keeping, I want to store my other important logs as well.

Below is a screenshot of my logs file Log File on IIS Code Snippet : in StartUp.cs configure method

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
        ILoggerFactory loggerFactory )
    {

        app.UseSession();
        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        loggerFactory.AddProvider(new CustomLoggerProvider(new CustomLoggerProviderConfiguration
        {
            LogLevel = LogLevel.Information
        },env.ContentRootPath));

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=test}/{action=test}/{id?}");
        });
    }

Code Snippet: Function which actually creates the file

        private void WriteToLog(string message)
    {

        ////When Date change create new file.
        string filePath = _hostingPath + "\\test\\" + "Web_" + DateTime.Today.ToString("yyyy_MM_dd") + ".txt";

        FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Write);
        using (StreamWriter streamWriter = new StreamWriter(fs))
        {
            streamWriter.WriteLine(message);
            streamWriter.Close();
        }
    }

Also, I am aware that it is not a good practice to store the logs on server as it takes space overtime. Is there any other approach that can be suggested to store logs please do tell?

Moreover would appreciate help in this issue of LogLevel "Information" not showing on IIS.

0

There are 0 best solutions below