Logs are not generating on publish

Prathamesh Shende 376 Reputation points
2022-04-05T16:39:21.997+00:00

I configured Microsoft Logger in Blazor Wasm with Asp.net core web APi
but after publishing to server the logs are not generating in logs folder.

on local I seen logs running in console Windows after running the project but not on server.

I also set stdoutLog= true in web.config file
path is default = ./logs/stdout

what is the problem ? What I missed?

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,178 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,394 questions
{count} votes

Accepted answer
  1. AgaveJoe 26,136 Reputation points
    2022-04-05T19:48:58.78+00:00

    I'm going to assume that you want to persist Web API logs. The following are the steps to get logging working using the hosted Blazor WASM template in Visual studio.

    Update the weather forecast action to write some information to log.

    [HttpGet]
    public IEnumerable<WeatherForecast> Get()
    {
        _logger.LogInformation("This is an information log...");
        _logger.LogWarning("This is an warning log...");
        _logger.LogError("This is an error log...");
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
        {
            Date = DateTime.Now.AddDays(index),
            TemperatureC = Random.Shared.Next(-20, 55),
            Summary = Summaries[Random.Shared.Next(Summaries.Length)]
        })
        .ToArray();
    }
    

    Deploy the server application to the file system, pick a target folder, and set stdoutLogEnabled="true" in the web.config. Remember the target folder and path.
    In IIS manger create a new application pointing to the target folder. The folder where you deployed the server application.
    Set permissions on the folder so the application pool identity can write to the target folder. Right click the folder -> properties -> security. The application username is...

    IIS APPPOOL\NameOfYourApp
    

    Make sure the user has read/write access to the folder. If you do not remember what you named the application, just look in IIS.

    Browser the application from IIS or enter the URL in your browser.

    You should start seeing logs in .\logs. It might take a while. Stop and restart the application if you are impatient. The warning and error logs also end up in the Event Viewer. The event view will also show error if the application identity cannot write to the .\logs folder.

    If you want a different configuration then read the logging documentation and configure your application accordingly.

    0 comments No comments

0 additional answers

Sort by: Most helpful