In order to implement logging for Blazor server you would follow the same approach as you would for a .NET Core or ASP.NET Core application.
Namely in your Program.cs file you would need to modify the CreateHostBuilder method to configure your loggers in a manner such as
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
You could then inject an ILogger into your razor components or throughout the rest of your application using dependency injection.
public class AboutModel : PageModel
{
private readonly ILogger _logger;
public AboutModel(ILogger<AboutModel> logger)
{
_logger = logger;
}
public string Message { get; set; }
public void OnGet()
{
Message = $"About page visited at {DateTime.UtcNow.ToLongTimeString()}";
_logger.LogInformation(Message);
}
}
Be sure to check the Microsoft documentation for information on built in loggers, third party loggers, and just logging in general.