惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

博客园 - 网络来者

MES物料分摊 墨西哥 嘉兴 兼容车牌摄像头 和 tplink 摄像头的sdk开发包 集成 训练数字识别模型 tplink摄像头监控 mes测试机 redis vue学习 vue 系统文件结构 udp server 监听服务 第一个服务 c# 开发相关 openclaw 安装 c# 版本号 oracle 触发器 脚本方式安装Python 特定版本 idea 激活 Chrome MCP Server mcp ok mcp_server RepositoryItemGridLookUpEdit 使用 ok devexpress gridcontrol表格知识 winfrom 弹文本框 松下贴片机解锁 git 使用
Serilog日志组件使用
网络来者 · 2025-08-20 · via 博客园 - 网络来者

builder.Logging.ClearProviders(); // 移除默认的日志提供程序 Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft.AspNetCore.Hosting", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.AspNetCore.Mvc", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.AspNetCore.Routing", LogEventLevel.Warning) .WriteTo.Console() .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200")) { // 基本配置 AutoRegisterTemplate = true, // 自动创建/更新索引模板 (适用于 ES 7.x/8.x) AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7, // 指定模板版本 (ESv8 for ES 8.x, ESv7 for ES 7.x) IndexFormat = "logs-{0:yyyy.MM.dd}", // 索引名称格式,按天滚动 TemplateName = "serilog-events-template", // 模板名称 NumberOfShards = 1, // 分片数 NumberOfReplicas = 1, // 副本数 // 批处理配置 BatchPostingLimit = 1000, // 每批发送的最大日志数 Period = TimeSpan.FromSeconds(5), // 批处理间隔时间 // 连接和重试配置 ConnectionTimeout = TimeSpan.FromSeconds(10), // EmitLogEvent = true, // 是否发送完整的 LogEvent 对象 (默认 true) // 认证 (如果 Elasticsearch 需要) // 如果你的 Elasticsearch 有用户名密码 // ModifyConnectionSettings = connectionConfiguration => connectionConfiguration // .BasicAuthentication("your-username", "your-password"), // 如果是 HTTPS 且需要忽略证书验证 (仅限开发环境!) // ModifyConnectionSettings = connectionConfiguration => connectionConfiguration // .ServerCertificateValidationCallback((sender, certificate, chain, errors) => true), // (可选) 如果需要配置特定的序列化或日志属性 // CustomFormatter = new ElasticsearchJsonFormatter(), // 使用默认或自定义格式化器 }) .WriteTo.MSSqlServer(connectionString: "Server=localhost;Database=LogDb;Integrated Security=SSPI;Encrypt=True; TrustServerCertificate=True;" , sinkOptions: new MSSqlServerSinkOptions { TableName = "LogEvents", AutoCreateSqlTable = true }) .WriteTo.File("Logs/log-.txt", rollingInterval: RollingInterval.Day, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}") .CreateLogger(); builder.Host.UseSerilog(dispose: true);

  app.UseSerilogRequestLogging(); //一定不能少这一句