log4net的与TraceSource [英] log4net versus TraceSource

查看:233
本文介绍了log4net的与TraceSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个线程很多人都表示,他们使用log4net的。我TraceSources的粉丝,想知道为什么log4net的使用。

In this thread many people have indicated that they use log4net. I am a fan of TraceSources and would like to know why log4net is used.

下面就是为什么我喜欢的跟踪源:

Here is why I like trace sources:

  • 插拔式监听器 - XML,文本文件,控制台,事件日志,滚你自己
  • 在定制的跟踪开关(错误,警告,信息,详细的,开始,结束,自定义)
  • 定制配置。
  • 在日志记录应用程序块只是一个大集TraceListeners的
  • 活动的相关性/范围(比如,联想与特定客户ASP.NET请求中的所有日志
  • 在服务跟踪查看器,您可以直观反对单独这些活动事件
  • 所有这一切都在App.config中/ web.config中配置。

由于.NET框架内部使用TraceSources,这也给了我跟踪配置一个一致的方式 - 与log4net的,我必须配置log4net的以及TraceSources。

Since the .NET framework internally uses TraceSources, it also gives me a consistent way of configuring tracing - with log4net, I have to configure log4net as well as TraceSources.

这是什么log4net的给我说TraceSources不(或不能做的写了几个自定义TraceListeners的)?

What does log4net give me that TraceSources don't (or that couldn't be done by writing a couple of custom TraceListeners)?

推荐答案

我觉得log4net的是做每次您列出适合我。

I think that log4net is doing every that you listed for me.

可插拔听众听起来追加程序 - 有很多人,事实上我甚至砍死滚动日志文件始终.LOG(文件关联)结束,增加了CC域的电子邮件附加器,并最终调整我最喜欢的值的彩色控制台附加目的地。 如果我可以大胆 - 我的有色控制台的幸福:

Pluggable listeners sounds like appenders - there are lots of them and in fact I even hacked the rolling log file to always end in .log (for file associations), added a cc field to the email appender, and have finally tuned my favourite values for the colored console appender. If I may be so bold - my colored console happiness:

<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<!-- Can Use:
		Blue
		Green
		Red
		White
		Yellow
		Purple
		Cyan
		HighIntensity
		-->
<mapping>
  <level value="FATAL" />
  <foreColor value="Yellow, HighIntensity" />
  <backColor value="Red" />
</mapping>
<mapping>
  <level value="ERROR" />
  <foreColor value="White" />
  <backColor value="Purple, HighIntensity" />
</mapping>
<mapping>
  <level value="WARN" />
  <backColor value="Blue" />
  <foreColor value="White" />
</mapping>
<mapping>
  <level value="INFO" />
  <backColor value="Green" />
  <foreColor value="White" />
</mapping>
<mapping>
  <level value="DEBUG" />
  <foreColor value="White" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
  <!--<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />-->
  <!--<conversionPattern value="%-5level %file:%line - %message%newline" />-->
  <conversionPattern value="%level %logger:%line %newline     %message%newline" />
</layout>

可定制的跟踪开关:log4net的只配备了致命错误警告信息调试为了增加冗长。唯一一个我真正怀念的是审计谁,做乜记录。

Customisable trace switches: Log4net only comes with FATAL ERROR WARN INFO DEBUG in order of increasing verbosity. The only one I actually miss is AUDIT for who-did-what logging.

定制配置:我使用,我加载在运行时log4net.config文件(或写日志到c:\发牢骚,我找不到配置)

Customisable configuration: I use a log4net.config file which I load up at runtime (or write a log to c:\ whining that I can't find the config.)

    Try
        ' Get log4net configuration from file
        Dim logConfigFile As FileInfo
        logConfigFile = New FileInfo(".\log4net.config")

        If logConfigFile.Exists Then
            XmlConfigurator.Configure(logConfigFile)
        Else
            CreateEmergenceLogFile(logConfigFile.FullName)
        End If

    Catch ex As Exception
        Console.Out.WriteLine("Could not load the log4net config file")
    End Try

只是一个大集TraceListeners的:对不起,跳过那一个 - 我要你的话。

just a big set of TraceListeners: sorry skipping that one - I'll take your word for it.

相关活动/作用域:你的意思是像每个文件(阅读类)得到它自己的命名日志,可以有单独的日志级别阈值。事实上,你可以分段记录,即使在一个类(即实际上可能已发展到做太多...)

Correlation of activities/scopes: do you mean like every file (read class) gets it's own named log that can have separate log level thresholds. In fact you can segment logging even in a single class (that in truth may have grown to do too much ...)

在一个类文件:

    Private Shared _logger As log4net.ILog = _
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

Private Shared _loggerAttribute As log4net.ILog = _
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName & ".Attribute")

Private Shared _loggerCache As log4net.ILog = _
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName & ".Cache")

服务跟踪查看器:在log4net.config:

The Service Trace Viewer: in the log4net.config:

  <logger name="NipissingU.ADWrapper.EntryTools.Attribute">
    <level value="INFO" />
  </logger>
  <logger name="NipissingU.ADWrapper.EntryTools.Cache">
    <level value="WARN" />
  </logger>

所有这一切都在App.config中/ web.config中配置的:那也许是因为这是在ASP.NET好事,我不知道,但使得富客户端的bean计数的应用程序,当我喜欢一个独立的配置文件。

All of it is configurable in app.config/web.config: well maybe that is a good thing in ASP.NET, I don't know, but when making rich client bean counting apps I like a separate config file.

这里的一切都只是我自己的小窍门使用

Everything here is just my own little usage tricks.

心连心, -Mike

hth, -Mike

这篇关于log4net的与TraceSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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