当前位置:网站首页>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's plastic processing machinery market trend report, technological innovation and market forecast
- DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
- Configuration instance of Oracle listener server and client
- Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
- 表单传递时,如何隐式将值传过去
- Hair growth shampoo industry Research Report - market status analysis and development prospect forecast
- Sequence diagram data modeling and industrial chain analysis
- Can you really use MySQL explain?
- Market trend report, technical innovation and market forecast of taillight components in China
猜你喜欢
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
函數式接口,方法引用,Lambda實現的List集合排序小工具
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
Understand asp Net core - Authentication Based on jwtbearer
Position encoding practice in transformer
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
从数数开始
祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022
Application of clock wheel in RPC
Filtered off site request to
随机推荐
Accounting regulations and professional ethics [9]
China tall oil fatty acid market trend report, technical dynamic innovation and market forecast
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
Market trend report, technical innovation and market forecast of tetrabromophthalate (pht4 diol) in China
MFC implementation of ACM basic questions encoded by the number of characters
Research Report on market supply and demand and strategy of China's four sided flat bag industry
力扣今日题-1200. 最小绝对差
Opencv learning -- geometric transformation of image processing
Maximum subarray and matrix multiplication
~88 running people practice
Accounting regulations and professional ethics [7]
Research Report on market supply and demand and strategy of China's well completion equipment industry
SQL implements split
Expression #1 of ORDER BY clause is not in SELECT list, references column ‘d.dept_ no‘ which is not i
Sequence diagram data modeling and industrial chain analysis
What is torch NN?
tp配置多数据库
What is torch NN?
Firebird experience summary
Research Report on plastic recycling machine industry - market status analysis and development prospect forecast