Windows 서비스에서 Castle log4Net 기능을 사용하려고합니다. 로그를 작성하지 못해 콘솔 앱을 만들어서 먼저 작동 시키려고했습니다. 아직 로그 파일이 작성되지 않았습니다. 내가 잘못했거나 기쁘게 생각한 것은 무엇 이었습니까?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>
서비스에서 Logger = NullLogger.Instance를 설정하는 이유는 무엇입니까? – wageoghe
이 링크가 될 수도 있습니다. (http://stackoverflow.com/questions/2297282/logging-with-castle-facilities-logging-and-log4net) – prasy
감사합니다. 이미 그 링크를 보았습니다. –