question

PrathameshShende avatar image
0 Votes"
PrathameshShende asked PrathameshShende commented

Logs are not generating on publish

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?

windows-server-iisdotnet-aspnet-core-blazordotnet-aspnet-core-webapi
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Blazor WASM runs on the client. Why are you expecting logs on the server? Are you making Web API calls and the web api calls are not logged? If so, how did you configure logging? How are you writing the logs?

what is the problem ? What I missed?

We can only guess without your configuration and and example of writing to the log. You might start by reading the reference documentation to figure out where you made the mistake.

Logging in .NET Core and ASP.NET Core


0 Votes 0 ·

appsetting.json

"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},

program.cs (.net 6 asp.net core webapi)

builder.Logging.ClearProviders();
builder.Logging.AddSimpleConsole(options =>
{
options.IncludeScopes = true;
options.TimestampFormat = "\n[dd-MMM-yy hh:mm:ss]\n";
});


this the config i set

0 Votes 0 ·
AgaveJoe avatar image AgaveJoe PrathameshShende ·

You are not helping the community help you!

Do you have 3 projects, Server, Client, and Shared?

What are your expectations? What exactly are you trying to do? What environment is the configuration you are showing us for?

Please be specific because the code you shared formats a console logger.

0 Votes 0 ·

Hi @PrathameshShende ,

You need to share the code about how to use Logger and log what kind of message. Like this:

 public void OnGet()
     {
         Message = $"About page visited at {DateTime.UtcNow.ToLongTimeString()}";
         _logger.LogInformation(Message);
     }

Only the configuration in startup and appsetting is not enough. In addition, when you deploy it to IIS, how are the configuration and permissions of the application pool set?

The app pool must have write access to the location where the logs are written (use IIS AppPool{APP POOL NAME} to provide write permission, where the placeholder {APP POOL NAME} is the app pool name).


0 Votes 0 ·

I missed that.. I created folder but from ftp and forget to access from server.. thanks

0 Votes 0 ·

1 Answer

AgaveJoe avatar image
0 Votes"
AgaveJoe answered AgaveJoe edited

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.