当前位置:网站首页>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;
}
}
边栏推荐
- Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782
- How can programmers improve the speed of code writing?
- Market trend report, technical innovation and market forecast of electrochromic glass and devices in China and Indonesia
- 科普达人丨一文看懂阿里云的秘密武器“神龙架构”
- Principle and general steps of SQL injection
- Maximum subarray and matrix multiplication
- China tall oil fatty acid market trend report, technical dynamic innovation and market forecast
- Inside and outside: flow chart drawing elementary: six common mistakes
- Research Report on market supply and demand and strategy of China's well completion equipment industry
- Accounting regulations and professional ethics [10]
猜你喜欢
Smart Logistics Park supply chain management system solution: digital intelligent supply chain enables a new supply chain model for the logistics transportation industry
Cut! 39 year old Ali P9, saved 150million
Understand ThreadLocal in one picture
Object. Usage of keys()
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
一图看懂ThreadLocal
NoSQL之readis配置与优化(终章)
Why do you say that the maximum single table of MySQL database is 20million? Based on what?
智慧物流园区供应链管理系统解决方案:数智化供应链赋能物流运输行业供应链新模式
Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent
随机推荐
Sequence diagram data modeling and industrial chain analysis
Array filter fliter in JS
对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平
Vscode prompt Please install clang or check configuration 'clang executable‘
Hash table
L1-072 scratch lottery
Filtered off site request to
Firebird experience summary
Why do you say that the maximum single table of MySQL database is 20million? Based on what?
What is torch NN?
Can you really use MySQL explain?
Li Kou today's question -1200 Minimum absolute difference
. Net applications consider x64 generation
Principle and general steps of SQL injection
C# 实现 FFT 正反变换 和 频域滤波
Understand ThreadLocal in one picture
Daily notes~
周大福践行「百周年承诺」,真诚服务推动绿色环保
Lv166 turned over
.Net 应用考虑x64生成