Asp.Net Core 2.2,Visual Studio 2019,IIS 8.5(我认为)
我很困惑。在Asp.Net Core 2.2中,日志消息记录在哪里?我在文档中缺少某些内容。 Program.cs
和我的一个控制器的相关部分如下。我以为这些消息最终会出现在“应用程序事件”中,但是我什么也没看到。
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>();
}
}
控制器
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");
}
}
...
修改
基于以下后续问题:在遵循@RossBush共享链接的建议后,我评论了事件ID问题。 @陶洲接了这个。我看到类似以下的服务器eventLog消息:
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