c# - CaSTLe Windsor 在哪里以及如何建立伐木设施

标签 c# .net logging inversion-of-control castle-windsor

我对温莎城堡相当陌生,正在调查伐木设施的内部和外部。这似乎相当令人印象深刻,但我唯一无法解决的是温莎在我的类(class)中设置 Logger 属性的地方。如以下代码所示,如​​果类尚未设置但当 Resolve 完成运行时 Logger 属性已设置,则将 Logger 设置为 nullLogger。

private ILogger logger;

public ILogger Logger
{
    get
    {
        if (logger == null) 
            logger = NullLogger.Instance;
        return logger;
    }
    set { logger = value; }
}

所以我想知道 windsor 如何以及在何处设置我的 Logger 属性。

干杯 安东尼

最佳答案

记录器由记录工具设置,它在 <facilities> 中配置部分。例如,要使用 log4net,您的应用程序或 web.config 将如下所示:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/>
    </configSections>
<Configuration>

<castle>

    <facilities>
        <facility id="loggingfacility" 
             type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging" 
             loggingApi="log4net" 
             configFile="logging.config" />
    </facilities>

</castle>
</configuration>

关于c# - CaSTLe Windsor 在哪里以及如何建立伐木设施,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/245354/

相关文章:

c# - 让 ReSharper 尊重您对代码顺序的偏好

.net - 单步执行属性/函数 (F11) 无法按预期工作

logging - 如何使用Gunicorn执行日志旋转?

git - 如何在 git 日志图中显示相对提交号?

c# - 如何检查程序是否运行以及用户是否存在?

c# - System.IO.Compression DLL 丢失且可能存在版本冲突

c# - 在数据库中插入 1,000,000 行时超时(有时)

.net - 如何在 VB.NET 中切换大写锁定?

c# - 什么是好的、免费的 C# 单元测试覆盖工具?

python - 如何临时更改 kubernetes pod 的环境变量?