gpt4 book ai didi

c# - CaSTLe Log4Net 设施不记录

转载 作者:行者123 更新时间:2023-11-30 17:45:14 25 4
gpt4 key购买 nike

我正在尝试在 Windows 服务中使用 CaSTLe log4Net 工具。我无法让它写日志,所以我想我会创建一个控制台应用程序来尝试让它首先工作。我仍然没有看到写入的日志文件。我做错了什么或错过了什么?

namespace CastleLoggingFacilityWithLog4Net
{
class Program
{
private static IWindsorContainer _container;

static void Main(string[] args)
{

_container = new WindsorContainer();
_container.Register(Component.For<IService>().ImplementedBy<Service>().LifestyleTransient());
_container.AddFacility<LoggingFacility>(f => f.LogUsing(LoggerImplementation.Log4net));
//_container.Install(FromAssembly.This());

var service = _container.Resolve<IService>();
service.TestLogging();
}
}

public interface IService
{
void TestLogging();
}

public class Service : IService
{
private ILogger logger = NullLogger.Instance;

public void TestLogging()
{
Logger.Info("this is a test");
}

public ILogger Logger
{
get { return logger; }
set { logger = value; }
}

}
}

在log4net.config中添加我的log4net配置如下...

<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="logging\log.txt" />
<appendToFile value="true" />
<datePattern value="dd-MM-yyyy'.log'" />
<staticLogFileName value="false" />
<rollingStyle value="Date"/>
<maximumFileSize value="10MB" />
<maxSizeRollBackups value="5" />
<dateTimeStrategy type="log4net.Appender.RollingFileAppender+UniversalDateTime" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%utcdate %-5level %logger - %message%newline%exception" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</root>
</log4net>
</configuration>

最佳答案

事实证明,我的代码或配置没有任何问题。问题是 log4net 配置没有设置为复制到输出目录!遗憾的是,CaSTLe 或 log4net 都无法告诉我找不到日志文件。

关于c# - CaSTLe Log4Net 设施不记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28096093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com