dotnet Core Practice-Log Component Serilog

Source: Internet
Author: User
Tags dotnet

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.