我在过去几周开始工作(或尝试)简单的 MVC-App 通知。
我可以将信息记录到控制台,但是如何为 http-requests 的通知功能添加简单的文件记录器?从头开始,我可以通过大量工作实现它,但没有任何支持文件记录的功能。我找到了 Ilogger 来登录控制台。但是有没有一种简单的方法可以将 Ilogger 从日志记录切换到控制台日志记录到文件?
public class NotificationsController : ControllerBase
{
private readonly MyConfig config;
private readonly ILogger<NotificationsController> _logger;
public NotificationsController(MyConfig config, ILogger<NotificationsController> logger)
{
this.config = config;
_logger = logger;
}
[HttpGet]
public ActionResult<string> Get()
{
...
string Message = $"About page visited at {DateTime.UtcNow.ToLongTimeString()}";
_logger.LogInformation(Message);
...
https://github.com/microsoftgraph/msgraph-training-changenotifications/tree/live