当前位置:网站首页>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;
}
}
边栏推荐
- 一图看懂ThreadLocal
- egg. JS learning notes
- The content of the source code crawled by the crawler is inconsistent with that in the developer mode
- Understand ThreadLocal in one picture
- PyTorch深度学习快速入门教程
- Accounting regulations and professional ethics [9]
- Object.keys()的用法
- How can programmers improve the speed of code writing?
- Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
猜你喜欢
Vscode prompt Please install clang or check configuration 'clang executable‘
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
Embedded software architecture design - function call
TypeError: list indices must be integers or slices, not str
Overflow: the combination of auto and Felx
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
智慧物流园区供应链管理系统解决方案:数智化供应链赋能物流运输行业供应链新模式
建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力
Readis configuration and optimization of NoSQL (final chapter)
随机推荐
~88 running people practice
Accounting regulations and professional ethics [7]
Market trend report, technical innovation and market forecast of tetrabromophthalate (pht4 diol) in China
Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782
Research Report on market supply and demand and strategy of surgical stapler industry in China
表单传递时,如何隐式将值传过去
照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益
Accounting regulations and professional ethics [6]
Principle and general steps of SQL injection
. Net applications consider x64 generation
Object.keys()的用法
C # realizes FFT forward and inverse transformation and frequency domain filtering
C# 实现 FFT 正反变换 和 频域滤波
程序员怎么才能提高代码编写速度?
c# 实现定义一套中间SQL可以跨库执行的SQL语句
时序图数据建模与产业链分析
How to decrypt worksheet protection password in Excel file
FIREBIRD使用经验总结
How to "use" Perl modules in directories that are not in @inc- How do I 'use' a Perl module in a directory not in @INC?
安信证券网上开户安全吗 开户收费吗