使用[assembly:]进行log4net配置 [英] log4net configuration with [assembly:]

查看:102
本文介绍了使用[assembly:]进行log4net配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇以下行如何在程序集中配置log4net:

I was curious how the following line works for configuring log4net in an assembly:

[assembly: log4net.Config.XmlConfigurator(Watch=true)]

我猜想这个在运行时调用"main()"之前的某个时间被调用了,但是什么时候发生,这意味着什么?是否有其他框架/库使用此Assembly属性来加载这样的初始上下文?与在main()中调用"Configure"方法相比,执行此类操作是否有优点/缺点?

I'm guessing this gets called sometime before the runtime invokes "main()" but when does this occur, and what are the implications? Are there other frameworks/libraries that use this assembly attribute for loading an initial context like this? Are there any advantages/disadvantages for doing something like this, as opposed to calling a "Configure" method in main()?

推荐答案

这样做的好处是,代码是在主代码之前和静态初始化之前进行初始化的.

The advantages of doing this are that the code is initialised in advance of your main code and in advance of the static initialisation.

这意味着,例如,您可以在静态构造函数内使用log4net日志记录.如果没有预初始化log4net的方法,在静态构造函数中,您将永远无法确定代码是否已正确初始化.

This means that you can, for example, use log4net logging within a static-constructor. Without a way to pre-initialise log4net, in the static constructor you'd never know for certain that the code has been initialised correctly.

该区域似乎没有很好的文档记录(或者很容易找到),但是我认为被调用方法的初始化是在程序集加载时执行的.

This area doesn't seem to be very well documented (or easy to find anyway) but I assume that the initialisation of called methods is performed at Assembly-load time.

这篇关于使用[assembly:]进行log4net配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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