C# 中使用最广泛的日志框架是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1260157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the most widely-used logging framework in C#?
提问by Nosrama
I'm looking into how to implement logging in my C# app - its a DLL class library. What logging frameworks are most widely used - what would give users of my DLL the most flexibility and configurability? Is there a C# equivalent of log4j?
我正在研究如何在我的 C# 应用程序中实现日志记录 - 它是一个 DLL 类库。哪些日志框架使用最广泛 - 什么会给我的 DLL 用户最大的灵活性和可配置性?是否有等效于 log4j 的 C#?
采纳答案by Cagdas Altinkaya
2009 Answer:Equivalent of log4j for .NET platform is log4netand I am guessing it's widely used.
2009 年回答:.NET 平台的 log4j 的等价物是log4net,我猜它被广泛使用。
2019 Answer:Here are a variety of alternatives from https://github.com/quozd/awesome-dotnet/blob/master/README.md#logging:
2019 年答案:以下是来自https://github.com/quozd/awesome-dotnet/blob/master/README.md#logging的各种替代方案:
- Essential Diagnostics- Extends the inbuilt features of System.Diagnostics namespace to provide flexible logging
- NLog- NLog - Advanced .NET and Silverlight logging
- Logazmic- Open source NLog viewer for Windows
- ELMAH- Official ELMAH site
- Elmah MVC- Elmah for MVC
- Logary- Logary is a high performance, multi-target logging, metric, tracing and health-check library for Mono and .NET. .NET's answer to DropWizard. Supports many targets, built for micro-services.
- Log4Net- The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets
- com.csutil.Log- A lightweight zero config Log wrapper that can be combined with other logging libraries like Serilog for more complex usecases.
- Serilog- A no-nonsense logging library for the NoSQL era. Combines the best of traditional and structured diagnostic logging in an easy-to-use package.
- StackExchange.Exceptional- Error handler used for the Stack Exchange network
- Semantic Logging Application Block (SLAB)- Extends the inbuilt features of System.Diagnostics.Tracing namespace (EventSource class) to log to several sinks including Azure Tables, Databases, files (JSON, XML, text). Supports in-process and out-of-process logging through ETW, and Rx for real-time filtering/aggregating of events.
- Foundatio- A fluent logging API that can be used to log messages throughout your application.
- Exceptionless- Exceptionless .NET Client
- Loupe- Centralized .NET logging and monitoring. [Proprietary][Free Tier]
- elmah.io- Cloud logging for .NET web applications using ELMAH. Find bugs before you go live. Powerful search, API, integration with Slack, GitHub, Visual Studio and more. [Free for OSS][$]
- BugSnag- Logs errors. Includes useful diagnostic info like stack trace, session, release, etc. Has a free tier. [Free for OSS][$]
- Essential Diagnostics- 扩展 System.Diagnostics 命名空间的内置功能以提供灵活的日志记录
- NLog- NLog - 高级 .NET 和 Silverlight 日志记录
- Logazmic- 适用于 Windows 的开源 NLog 查看器
- ELMAH- ELMAH 官方网站
- Elmah MVC- 用于 MVC 的 Elmah
- Logary- Logary 是用于 Mono 和 .NET 的高性能、多目标日志记录、度量、跟踪和健康检查库。.NET 对 DropWizard 的回答。支持多种目标,为微服务构建。
- Log4Net- Apache log4net 库是帮助程序员将日志语句输出到各种输出目标的工具
- com.csutil.Log- 一个轻量级的零配置日志包装器,可以与其他日志库(如 Serilog)结合用于更复杂的用例。
- Serilog- NoSQL 时代的严肃日志库。将最好的传统和结构化诊断日志记录在一个易于使用的包中。
- StackExchange.Exceptional- 用于 Stack Exchange 网络的错误处理程序
- 语义日志记录应用程序块 (SLAB)- 扩展 System.Diagnostics.Tracing 命名空间(EventSource 类)的内置功能,以记录到多个接收器,包括 Azure 表、数据库、文件(JSON、XML、文本)。支持通过 ETW 和 Rx 进行进程内和进程外日志记录,用于实时过滤/聚合事件。
- Foundatio- 一个流畅的日志 API,可用于在整个应用程序中记录消息。
- Exceptionless- Exceptionless .NET 客户端
- Loupe- 集中的 .NET 日志记录和监控。[专有] [免费等级]
- elmah.io- 使用 ELMAH 的 .NET Web 应用程序的云日志记录。在上线之前发现错误。强大的搜索、API、与 Slack、GitHub、Visual Studio 等的集成。[ OSS 免费] [$]
- BugSnag- 记录错误。包括有用的诊断信息,如堆栈跟踪、会话、发布等。有一个免费层。[OSS免费][$]
回答by ozczecho
Have used NLog successfully in numerous projects.
已在众多项目中成功使用 NLog。
回答by twk
I am using NLog from years with success and it is very well done project.
我多年来成功使用 NLog,这是一个非常出色的项目。
回答by azheglov
回答by Robert Koritnik
People have been using Enterprise Libraryextensively. But it may be true that developers are switching to other products these days.
人们一直在广泛使用企业库。但是,如今开发人员正在转向其他产品,这可能是真的。
I'd check it out and see if it has the necessary functionality you need and not too much bloat.
我会检查一下,看看它是否具有您需要的必要功能,并且没有太多膨胀。
回答by Punit Vora
Enterprise Library.It's robust and comes straight from Microsoft with all their best practices included. We use it in all our projects. It's very flexible and there is a UI tool that you can use in case you don't want to mess around with managing logging from the config file.
企业图书馆。它很健壮,直接来自 Microsoft,包括他们的所有最佳实践。我们在所有项目中都使用它。它非常灵活,并且有一个 UI 工具可供您使用,以防您不想从配置文件管理日志记录。
回答by gef
log4net is almost certainly the most common.
log4net 几乎可以肯定是最常见的。
But I use Common.Logging - http://netcommon.sourceforge.net/as it gives me flexibility
但我使用 Common.Logging - http://netcommon.sourceforge.net/因为它给了我灵活性
There are a variety of logging implementations for .NET currently in use, log4net, Enterprise Library Logging, NLog, to name the most popular. The downside of having differerent implementation is that they do not share a common interface and therefore impose a particular logging implementation on the users of your library.
Common.Logging library introduces a simple abstraction to allow you to select a specific logging implementation at runtime. Thus you can defer the decision what particular logging library to use until deployment. Adapters are used for plugging a particular logging system into Common.Logging.
当前使用的 .NET 有多种日志记录实现,log4net、企业库日志记录、NLog 等最流行。具有不同实现的缺点是它们不共享公共接口,因此对库的用户强加了特定的日志记录实现。
Common.Logging 库引入了一个简单的抽象,允许您在运行时选择特定的日志记录实现。因此,您可以推迟决定使用哪个特定的日志库,直到部署。适配器用于将特定的日志系统插入 Common.Logging。