实例介绍
Serilog.Sinks.Http是一个支持将日志事件通过HTTP发送的Serilog日志接收器。它支持.NET 4.5/4.6.1和.NET Standard 2.0/2.1等平台,旨在简化日志数据的远程传输过程。
本项目最初目的是为了将日志事件发送到Elastic Stack,基于对Elastic Filebeat的使用体验,开发者决定创造一个更通用的HTTP日志接收器。通过使用命名参数配置,该接收器能够在不更改代码的情况下轻松升级。
ILogger log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Http(requestUri: "https://www.mylogs.com", queueLimitBytes: null)
.CreateLogger();
log.Information("Logging {@Heartbeat} from {Computer}", heartbeat, computer);
此外,Serilog.Sinks.Http还支持持久化日志事件到磁盘,以防系统或进程重启后数据丢失。批处理功能可以将多个日志事件合并为单个请求,以JSON格式发送。
典型应用场景包括从Docker容器发送日志事件、直接发送至Elasticsearch或通过Logstash进行进一步处理。该项目还提供了多个示例应用程序,展示了在不同上下文中如何使用该接收器。
要在项目中引入HTTP日志接收器,可以通过NuGet安装。
【实例截图】
【核心代码】
文件清单
└── serilog-sinks-http-1eb76e7c9589ca8e27a118e817863b8857466cb8
├── appveyor.yml
├── build
│ └── build.ps1
├── CHANGELOG.md
├── CONTRIBUTING.md
├── coverlet.runsettings
├── Directory.Build.props
├── LICENSE
├── README.md
├── renovate.json
├── serilog-sinks-http.sln
├── serilog-sinks-http.sln.DotSettings
├── serilog.snk
├── src
│ └── Serilog.Sinks.Http
│ ├── assets
│ │ └── serilog-sink-nuget.png
│ ├── LoggerSinkConfigurationExtensions.cs
│ ├── Serilog.Sinks.Http.csproj
│ └── Sinks
│ └── Http
│ ├── BatchFormatters
│ │ └── ArrayBatchFormatter.cs
│ ├── BufferRollingInterval.cs
│ ├── ByteSize.cs
│ ├── HttpClients
│ │ ├── JsonGzipHttpClient.cs
│ │ └── JsonHttpClient.cs
│ ├── IBatchFormatter.cs
│ ├── IHttpClient.cs
│ ├── Private
│ │ ├── Durable
│ │ │ ├── Batch.cs
│ │ │ ├── BookmarkFile.cs
│ │ │ ├── BufferFileReader.cs
│ │ │ ├── BufferRollingIntervalExtensions.cs
│ │ │ ├── FileSizeRolledBufferFiles.cs
│ │ │ ├── FileSizeRolledDurableHttpSink.cs
│ │ │ ├── HttpLogShipper.cs
│ │ │ ├── IBufferFiles.cs
│ │ │ ├── TimeRolledBufferFiles.cs
│ │ │ └── TimeRolledDurableHttpSink.cs
│ │ ├── Encoding.cs
│ │ ├── IO
│ │ │ └── DirectoryService.cs
│ │ ├── NonDurable
│ │ │ ├── Batch.cs
│ │ │ ├── HttpSink.cs
│ │ │ ├── LogEventQueue.cs
│ │ │ └── LogEventQueueReader.cs
│ │ └── Time
│ │ ├── ExponentialBackoffConnectionSchedule.cs
│ │ └── PortableTimer.cs
│ └── TextFormatters
│ ├── CompactRenderedTextFormatter.cs
│ ├── CompactTextFormatter.cs
│ ├── NamespacedTextFormatter.cs
│ ├── NormalRenderedTextFormatter.cs
│ ├── NormalTextFormatter.cs
│ └── ValueFormatter.cs
└── test
├── Serilog.Sinks.HttpTests
│ ├── appsettings_durable_http_using_file_size_rolled_buffers.json
│ ├── appsettings_durable_http_using_time_rolled_buffers.json
│ ├── appsettings_http.json
│ ├── DurableHttpSinkUsingFileSizeRolledBuffersGivenAppSettingsShould.cs
│ ├── DurableHttpSinkUsingFileSizeRolledBuffersGivenCodeConfigurationShould.cs
│ ├── DurableHttpSinkUsingTimeRolledBuffersGivenAppSettingsShould.cs
│ ├── DurableHttpSinkUsingTimeRolledBuffersGivenCodeConfigurationShould.cs
│ ├── Extensions
│ │ └── Xunit
│ │ └── TheoryOnMainBranch.cs
│ ├── HttpSinkGivenAppSettingsShould.cs
│ ├── HttpSinkGivenCodeConfigurationShould.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Serilog.Sinks.HttpTests.csproj
│ ├── Sinks
│ │ └── Http
│ │ ├── BatchFormatters
│ │ │ └── ArrayBatchFormatterShould.cs
│ │ ├── ByteSizeShould.cs
│ │ ├── Private
│ │ │ ├── Durable
│ │ │ │ ├── BufferFileReaderShould.cs
│ │ │ │ ├── BufferRollingIntervalExtensionsShould.cs
│ │ │ │ ├── FileSizeRolledBufferFilesShould.cs
│ │ │ │ ├── FileSizeRolledDurableHttpSinkShould.cs
│ │ │ │ ├── TimeRolledBufferFilesShould.cs
│ │ │ │ └── TimeRolledDurableHttpSinkShould.cs
│ │ │ ├── IO
│ │ │ │ └── DirectoryServiceMock.cs
│ │ │ ├── NonDurable
│ │ │ │ ├── HttpSinkShould.cs
│ │ │ │ ├── LogEventQueueReaderShould.cs
│ │ │ │ └── LogEventQueueShould.cs
│ │ │ └── Time
│ │ │ └── ExponentialBackoffConnectionScheduleShould.cs
│ │ └── TextFormatters
│ │ ├── CompactTextFormatterShould.cs
│ │ ├── NamespacedTextFormatterShould.cs
│ │ └── NormalTextFormatterShould.cs
│ ├── Support
│ │ ├── Fixtures
│ │ │ ├── GitHubWikiFixture.cs
│ │ │ ├── WebServerFixture.cs
│ │ │ └── XmlDocumentationFixture.cs
│ │ ├── HttpClientMock.cs
│ │ ├── NastyException.cs
│ │ ├── Randomize.cs
│ │ ├── Reflection
│ │ │ ├── FileSizeRolledDurableHttpSinkReflection.cs
│ │ │ ├── HttpSinkReflection.cs
│ │ │ ├── ReflectionExtensions.cs
│ │ │ └── TimeRolledDurableHttpSinkReflection.cs
│ │ ├── Sinks
│ │ │ └── TextWriterSink.cs
│ │ ├── Some.cs
│ │ ├── TaskFactoryExtensions.cs
│ │ └── TextFormatters
│ │ └── NormalTextLogEvent.cs
│ └── WikiPageDocumentationShould.cs
└── Serilog.Sinks.HttpTests.LogServer
├── appsettings.Development.json
├── appsettings.json
├── Controllers
│ ├── LogEventController.cs
│ └── LogEventDto.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
├── Serilog.Sinks.HttpTests.LogServer.csproj
├── Services
│ ├── HealthService.cs
│ ├── LogEvent.cs
│ └── LogEventService.cs
└── Startup.cs
38 directories, 100 files
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论