当前位置:网站首页>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;
}
}
边栏推荐
- 高度剩余法
- .Net 应用考虑x64生成
- Research Report of exoskeleton robot industry - market status analysis and development prospect prediction
- Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent
- Final consistency of MESI cache in CPU -- why does CPU need cache
- How to contribute to the source code of ongdb core project
- Vscode prompt Please install clang or check configuration 'clang executable‘
- [Chongqing Guangdong education] National Open University spring 2019 1248 public sector human resource management reference questions
- Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?
- Vscode setting outline shortcut keys to improve efficiency
猜你喜欢
Software Engineer vs Hardware Engineer
时钟轮在 RPC 中的应用
Yanwen logistics plans to be listed on Shenzhen Stock Exchange: it is mainly engaged in international express business, and its gross profit margin is far lower than the industry level
一图看懂ThreadLocal
What is torch NN?
函數式接口,方法引用,Lambda實現的List集合排序小工具
TypeError: list indices must be integers or slices, not str
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
嵌入式软件架构设计-函数调用
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
随机推荐
What is torch NN?
The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time
China Indonesia adhesive market trend report, technological innovation and market forecast
Software Engineer vs Hardware Engineer
Detailed process of DC-2 range construction and penetration practice (DC range Series)
Hair growth shampoo industry Research Report - market status analysis and development prospect forecast
同构图与异构图CYPHER-TASK设计与TASK锁机制
Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782
Height residual method
Overflow: the combination of auto and Felx
C # realizes FFT forward and inverse transformation and frequency domain filtering
Research Report on plastic recycling machine industry - market status analysis and development prospect forecast
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
tp配置多数据库
go-micro教程 — 第二章 go-micro v3 使用Gin、Etcd
Accounting regulations and professional ethics [11]
Transformer中position encoding实践
PyTorch深度学习快速入门教程
表单传递时,如何隐式将值传过去
Position encoding practice in transformer