当前位置:网站首页>C# 服务器日志模块
C# 服务器日志模块
2022-07-04 15:08:00 【帅_shuai_】
C# 服务器日志模块
给我们的服务器配置日志,这样我们可以按照规则(比如按照 月/天/小时 这样这样的结构把日志打印到对应的文件里),这样我们把日志文件分割在按照 年月日命名 生成的日志文件里,防止单个日志文件过大
使用NuGet包中的Serilog包来对日志进行收集
<ItemGroup>
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
- 创建类库程序,便于生成DLL对外部直接使用
- 对其进行二次封装
public class Logger
{
private static Serilog.Core.Logger coreLogger;
private static Logger warpLogger;
public static Serilog.Core.Logger Instance => coreLogger;
public Logger(string logFileName)
{
coreLogger = new LoggerConfiguration().
WriteTo.Console().
WriteTo.File($"{
logFileName}-.txt", rollingInterval: RollingInterval.Minute).
CreateLogger();
}
public static void Create(string logFileName)
{
warpLogger = (warpLogger == null) ? new Logger(logFileName) : warpLogger;
}
}

边栏推荐
- China Indonesia adhesive market trend report, technological innovation and market forecast
- 安信证券排名 网上开户安全吗
- How to implicitly pass values when transferring forms
- Median and order statistics
- Array filter fliter in JS
- 基于check-point机制的任务状态回滚和数据分块任务
- Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
- Communication mode based on stm32f1 single chip microcomputer
- Vscode setting outline shortcut keys to improve efficiency
- Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
猜你喜欢

~88 running people practice
Why do you say that the maximum single table of MySQL database is 20million? Based on what?

Understand ThreadLocal in one picture

Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?

Filtered off site request to

程序员怎么才能提高代码编写速度?

The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)

Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782

Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent

How to decrypt worksheet protection password in Excel file
随机推荐
Why do you say that the maximum single table of MySQL database is 20million? Based on what?
Redis: SDS source code analysis
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
Start by counting
Position encoding practice in transformer
What is torch NN?
How to implicitly pass values when transferring forms
Research Report on market supply and demand and strategy of surgical stapler industry in China
Daily notes~
NoSQL之readis配置与优化(终章)
Lv166 turned over
ECCV 2022放榜了:1629篇论文中选,录用率不到20%
Software Engineer vs Hardware Engineer
智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Maximum subarray and matrix multiplication
Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent
Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?
Research Report on surgical otorhinolaryngology equipment industry - market status analysis and development prospect prediction
Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782