0

Asp.Net Core 2.2, Visual Studio 2019, IIS 8.5 (I think)

I am stumped. In Asp.Net Core 2.2 where are log messages logged? I am missing something in the docs. The relevant sections of the Program.cs and one of my controllers are below. I have assumed that the messages would end up in the Application Events but I am not seeing anything.

Program.cs

public class Program {
    public static void Main(string[] args) {
        CreateWebHostBuilder(args).Build().Run();
    }

    private static IWebHostBuilder CreateWebHostBuilder(string[] args) {
        return WebHost.CreateDefaultBuilder(args)
            .UseIIS()
            .ConfigureLogging((hostingContext, logging) => {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddDebug();
                logging.AddEventSourceLogger();
                logging.SetMinimumLevel(LogLevel.Debug);
            })
            .UseStartup<Startup>();
    }
}

A Controller

public class AuthController : Controller {
    private readonly ILogger _logger;

    public AuthController(ILogger<AuthController> logger) {
        _logger = logger;
    }

    [HttpGet]
    public ActionResult Index() {
        try {
            _logger.LogDebug("Auth/Index: redirecting to /Auth/Login");
            return Redirect("/Auth/Login");
        } catch (Exception e) {
            return Redirect("/Reservation/Index" + "?error=LOGIN_ERROR");
        }
    }

    ...

Edit

Based on a followup question below: After following advice from the link @RossBush shared I commented about having event Id issues. @TaoZhou picked up on that. I am seeing server eventLog messages like:

The description for Event ID 2 from source Application cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

Microsoft.AspNetCore.Hosting.Internal.WebHost
Request finished in 24.4311ms 302 

the message resource is present but the message is not found in the string/message table
7 Reeds
  • 2,419
  • 3
  • 32
  • 64
  • Do you have a section "Logging" in your configuration, if so can you post it? – Ross Bush May 29 '19 at 19:13
  • Not at this instant. Looking at the doc examples, it was not clear that that was necessary. I can work on that though. – 7 Reeds May 29 '19 at 19:38
  • 2
    Take a look at this, perhaps this helps solve the issue you are having. -->https://stackoverflow.com/questions/52310072/log-to-event-viewer-in-an-asp-net-core-2-1-web-api – Ross Bush May 29 '19 at 19:46
  • Thanks, that link has helped. things are trying to reach the event log but there are event ID issues. I'll follow that for a while – 7 Reeds May 29 '19 at 20:50
  • What do you mean by `event id issues`? – Edward May 30 '19 at 02:21

0 Answers0