a few days ago the Quartz.net-based part of the project code was ported to Dotnet Core, but the log function was not added because no suitable components were found.
Today, we finally found Serilog: https://github.com/serilog/serilog
Source
Let's talk about:
1, VS 2015 new Console application (. NET Core) project.
2, Package Manager console:
Install the following components: Serilog,serilog.sinks.literate,serilog.sinks.rollingfile
or Project.json configuration:
"Serilog": "2.2.0",
"Serilog.Sinks.Literate": "2.0.0",
"Serilog.Sinks.RollingFile": "3.0.0"
3, write point code:
usingSerilog;usingSystem;namespaceconsoleapp{ Public classProgram { Public Static voidMain (string[] args) {Log.logger=Newloggerconfiguration (). Minimumlevel.debug ()//level. Writeto.literateconsole ()//Write to console. Writeto.rollingfile ("Logs\\{date}.txt")//Write to Text . Createlogger (); Log.information ("Hello, world!."); intA =Ten, B =0; Try{log.debug ("dividing {A} by {B}", A, b); Console.WriteLine (A/b); } Catch(Exception ex) {Log.error (ex,"Something went wrong"); } log.closeandflush (); Console.readkey (); } }}
4, run down to see:
dotnet Core Practice-Log Component Serilog