Asp.net core 2.0 Microsoft. Extensions. Logging text file log extension,
Microsoft officially provides native support for logs for asp.net core, which has the following implementation:
- Console
- Debug
- EventLog
- AzureAppServices
- TraceSource
- EventSource
By default, Comsole and Debug log output are enabled in the asp.net core Project template.
In actual production, it is not enough to output logs only on the console. We hope to use persistent carriers, such as text txt files.
Huanent. Logging. File is the implementation of Microsoft. Extensions. Logging text File logs. It is easy to use and detailed steps have been written on github.
Https://github.com/huanent/Huanent.Logging
Configuration instructions:
You can Install-Package Huanent. logging. file to install and expand, or search for Huanent in the nuget package browser. logging. after installing and configuring the plug-in, your asp.net core program will save the output logs to the logs folder under the program root directory, and divide the File name by date. install Huanent. logging. file2. in Program. add in cs File
Public static IWebHost BuildWebHost (string [] args) => WebHost. createdefabuilder Builder (args ). useStartup <Startup> () manually highlight -->. configureLogging (builder => builder. addFile ()). build ();
3. Configure the appsettings. json File and add a File node.
{"Logging": {"IncludeScopes": false, "Debug": {"LogLevel": {"Default": "Warning" }}, "Console ": {"LogLevel": {"Default": "Warning" }}, manual highlight --> "File": {manual highlight --> "LogLevel ": {manual highlight --> "Default": "Wanring" // you can modify the specific input level. You can also add a detailed category-based output manual highlight -- >} manual highlight --> }}}
Configuration complete
To reduce the impact of file read/write on performance, the plug-in maintains a message queue, asynchronously stores message logs, and has a low-configuration cpu (surface pro4 core M3) on the local machine) the number of writes per second in the test is more than 1000, which is sufficient for large projects.