1.安装NuGet安装
2.LogSerilog.cs类代码如下:
using Serilog;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinFormPro
{
public class LogSerilog
{
private LogSerilog(string name)
{
string SerilogOutputTemplate = “Date:{Timestamp:yyyy-MM-dd HH:mm:ss.fff}{NewLine}LogLevel:{Level}{NewLine}Message:{Message}{NewLine}{Exception}” + new string(‘-’, 50) + “{NewLine}{NewLine}”;
log = new LoggerConfiguration().MinimumLevel.Debug()
.WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Debug).WriteTo.Async(t => t.File( " L o g / n a m e / n a m e . l o g " , r o l l i n g I n t e r v a l : R o l l i n g I n t e r v a l . D a y , r e t a i n e d F i l e C o u n t L i m i t : 24 , b u f f e r e d : f a l s e , s h a r e d : t r u e , o u t p u t T e m p l a t e : S e r i l o g O u t p u t T e m p l a t e ) ) ) . W r i t e T