Snapshot của serilog/serilog: 8.0k★ · C#. Simple .NET logging with fully-structured events
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Serilog is a diagnostic logging library for .NET applications. It is easy to set up, has a clean API, and runs on all recent .NET platforms. While it's useful even in the simplest applications, Serilog's support for structured logging shines when instrumenting complex, distributed, and asynchronous applications and systems.
Like many other libraries for .NET, Serilog provides diagnostic logging to files, the console, and many other outputs.
using var log = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("log.txt")
.CreateLogger();
log.Information("Hello, Serilog!");
Unlike other logging libraries, Serilog is built from the ground up to record structured event data.
var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 34;
log.Information("Processed {@Position} in {Elapsed} ms", position, elapsedMs);
Serilog uses message templates, a simple DSL that extends .NET format strings with named as well as positional parameters. Instead of formatting events immediately into text, Serilog captures the values associated with each named parameter.
The example above records two properties, Position and Elapsed, in the log event. The @ operator in front of Position tells Serilog to serialize the object passed in, rather than convert it using ToString(). Serilog's deep and rich support for structured event data opens up a huge range of diagnostic possibilities not available when using traditional loggers.
Rendered into JSON format for example, these properties appear alongside the timestamp, level, and message like:
Back-ends that are capable of recording structured event data make log searches and analysis possible without log parsing or regular expressions.
Supporting structured data doesn't mean giving up text: when Serilog writes events to files or the console, the template and properties are rendered into friendly human-readable text just like a traditional logging library would produce:
09:14:22 [INF] Processed {"Latitude": 25, "Longitude": 134} in 34 ms.
Upgrading from an earlier Serilog version? Find release notes here.
Features
Community-backed and actively developed
Format-based logging API with familiar levels like Debug, Information, Warning, Error, and so-on
Discoverable C# configuration syntax and optional XML or JSON configuration support
Efficient when enabled, extremely low overhead when a logging level is switched off
Best-in-class .NET Core support, including rich integration with ASP.NET Core
Support for a comprehensive range of sinks, including files, the console, on-premises and cloud-based log servers, databases, and message queues
Sophisticated enrichment of log events with contextual information, including scoped (LogContext) properties, thread and process identifiers, and domain-specific correlation ids such as HttpRequestId
Zero-shared-state Logger objects, with an optional global static Log class
Format-agnostic logging pipeline that can emit events in plain text, JSON, in-memory LogEvent objects (including Rx pipelines) and other formats
Getting started
Serilog is installed from NuGet. To view log events, one or more sinks need to be installed as well, here we'll use the pretty-printing console sink, and a rolling file set:
The simplest way to set up Serilog is using the static Log class. A LoggerConfiguration is used to create and assign the default logger, normally in Program.cs:
using Serilog;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("log.txt",
rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true)
.CreateLogger();
try
{
// Your program here...
const string name = "Serilog";
Log.Information("Hello, {Name}!", name);
throw new InvalidOperationException("Oops...");
}
catch (Exception ex)
{
Log.Error(ex, "Unhandled exception");
}
finally
{
await Log.CloseAndFlushAsync(); // ensure all logs written before app exits
}
Find more, including a runnable example application, under the Getting Started topic in the documentation.
Getting help
To learn more about Serilog, check out the documentation - you'll find information there on the most common scenarios. If Serilog isn't working the way you expect, you may find the troubleshooting guide useful.
Serilog has an active and helpful community who are happy to help point you in the right direction or work through any issues you might encounter. You can get in touch via:
Stack Overflow — this is the best place to start if you have a question. Many track the serilog tag there.
The #serilog tag on Twitter
Serilog-related courses on Pluralsight
We welcome reproducible bug reports and detailed feature requests through our GitHub issue tracker;
note the other resource are much better for quick questions or seeking usage help.
Contributing
Would you like to help make Serilog even better? We keep a list of issues that are approachable for newcomers under the up-for-grabs label (accessible only when logged into GitHub). Before starting work on a pull request, we suggest commenting on, or raising, an issue on the issue tracker so that we can help and coordinate efforts. For more details check out our contributing guide.
When contributing please keep in mind our Code of Conduct.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/serilog/serilog là nguồn chính thức.
serilog/serilog có bao nhiêu sao?
serilog/serilog có 8.0k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/serilog/serilog. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
serilog/serilog có những chủ đề gì?
GitHub topics của serilog/serilog: "serilog". TopGit xếp repo vào nhóm mã nguồn mở.
serilog/serilog có trang demo không?
Dự án có trang chủ ở https://serilog.net. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
serilog/serilog còn đang phát triển không?
Commit gần nhất trên serilog/serilog là 22 ngày trước (theo timestamp GitHub). Repo có 863 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
serilog/serilog dùng license gì?
serilog/serilog phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
serilog/serilog viết bằng ngôn ngữ gì?
serilog/serilog chủ yếu viết bằng C#. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về serilog?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về serilog.