ASP.NET Core learning --5

Log (Logging)
ASP.NET built-in support Core logging, but also allows developers to easily switch to another logging framework for them to want to use.

By request ILoggerFactory dependency-injection or ILogger <T>, you can increase the logging application. If requested ILoggerFactory, then the logger must use its CreateLogger method.
loggerFactory.CreateLogger Logger = var ( "Catchall Endpoint");
logger.LogInformation ( "No Request for Endpoint found path {}", context.Request.Path);


When an application adds a logging, you must specify the log level. In ASP.NET Core exhaustively defines six log level, by increasing the importance or severity of the sort.

1, Trace
used to record the most detailed log messages, typically used for the development phase to debug problems.
Because these messages may contain sensitive application data, and is not recommended for production environments, should be disabled by default.

2, Debug
such messages more useful during the development phase the short term.
They contain some of the information might be helpful to debug, but no long-term value.
By default, this is the most detailed log.

3, Information
This message is used to track the flow of general application.
This log has some long-term value.

4, Warning
when an application does not lead to an error or other program to stop the flow of abnormal or unexpected event, you should use the warning level ,, for future investigation.
Recommended warning level exception handling in a common place.

5, Error
when an application to stop working due to some fault, you need to log errors.
The message should indicate the current activity or operation (such as the current HTTP request), instead of failing application range.

6, Critical
when an application or system crashes, suffers a catastrophic failure, when in need of immediate attention, the key level logging should be recorded. For example, data loss, insufficient disk space and so on.

Guess you like

Origin www.cnblogs.com/ahao214/p/11368739.html