有没有在.NET中内置的日志框架? [英] Is there a built-in logging framework in .NET?

查看:128
本文介绍了有没有在.NET中内置的日志框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单问题:看到标题。我使用.NET 3.5。

Simple question: see title. I'm using .NET 3.5.

阐述: 我建设将被加载到在运行第三方应用程序的插件。主要的应用程序使用的log4net作为日志框架。但是,它不公开根记录器,所以我们是无法登录。 (我已经与上游的开发商提出了这个问题,他们将它固定在以后的版本所以在此期间,我需要拿出别的东西)

Elaboration: I'm building a plugin that will be loaded into a 3rd party application at runtime. The main application uses log4net as its logging framework. However, it doesn't expose the root logger so we're unable to log. (I've raised this issue with the upstream developers and they'll be fixing it for a future release so in the meantime I need to come up with something else)

该系统的另一个限制是,当它接收通知,它应该加载不本地系统上存在一个插件,它将拉低该插件从它被连接到(如果它存在于服务器上的服务器),但它只能拉下,其中插件所居住的组装。这意味着无需外部组件和无的.config或其他任何文件都可以部署该插件。

Another limitation of the system is that when it receives notification that it should load a plugin which doesn't exist on the local system, it will pull down that plugin from a server it is connected to (if it exists on the server), but it can only pull down the assembly where the plugin lives. This means no external assemblies and no .config or any other files can be deployed with the plugin.

这给我留下唯一内置.NET程序集,一切都在我的插件'组装。但是,我并不想通过建立自己的又一日志框架重新发明轮子,所以我想知道这个问题的最好办法是。

That leaves me with only built-in .NET assemblies and everything in my plugins' assembly. However, I don't want to be reinventing the wheel by building myself Yet Another Logging Framework so I'd like to know what the best approach to this problem would be.

我倒是preFER记录到一个文件,并想避免倾倒的东西到Windows事件日志。

I'd prefer logging to a file and would like to avoid dumping stuff into the Windows event log.

推荐答案

两个主要选择是在那里:

Two main options are out there:

跟踪调试类,它们是.NET框架的一部分(在 System.Diagnostics程序命名空间)可能是你最好的选择。这些提供的工具做轻量记录到各种运行时配置的听众,也可以写入文件,事件日志等几个地方。

The Trace and Debug classes which are part of the .NET framework (within the System.Diagnostics namespace) are probably your best bet. These provide the tools to do lightweight logging to a variety of runtime configurable listeners, that can write to file, eventlog and several other places.

这听起来像你不能添加任何额外的类到你的应用程序,但如果你能那么我建议微软企业库,这虽然是外部的日志框架,由微软提供,并倾向于与发挥很好.NET code。

It sounds like you can't add any extra classes to your application, but if you can then I'd recommend the Microsoft Enterprise Library, which while being an external logging framework, is provided by Microsoft and tends to play nicely with .NET code.

这篇关于有没有在.NET中内置的日志框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆