Uygulamamdan bazı uygulama mesajlarını günlüğe kaydetmeyi denemek istiyorum. Bu durumda sadece rahibin log4net ile çalışmaya zorlanmasını istiyorum. Burada bir örnek buldum http://www.ofconsulting.com/PublicPortal/ofc-tech-blog/92-configure-log4net-with-nunit.html.log4net ve nunit testleri, en temel örnek
log4net böyle app.config confugured edilir:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
</log4net>
Ve benim test kodu
takip ediyor[TestFixture]
class DomainTests
{
protected static readonly ILog log = LogManager.GetLogger(typeof(DomainTests));
public void LoggingTests()
{
log4net.Config.XmlConfigurator.Configure();
}
[Test]
public void BasicLogTest()
{
log.Error("write my log entry already");
}
Testim geçirilir ama hiçbir şey log.txt dosyasının içinde yazılır . Neyi yanlış yapıyorum?
Sadece bir uygulama girmek, uygulamadan çıkmak gibi mesajları saklamak için mümkün olduğunca basit bir hale getirmek istiyorum. Saygılarımızla.
[TestFixture]
class DomainTests
{
protected static readonly ILog log = LogManager.GetLogger(typeof(DomainTests));
public void LoggingTests()
{
log4net.Config.XmlConfigurator.Configure();
}
[Test]
public void BasicLogTest()
{
log.Error("write my log entry already");
}
[SetUp]
RunBeforeAnyTests()
{
BasicConfigurator.Configure();
}
[TearDown]
RunAfterAnyTests()
{
// ...
}
Ben de Log4Net.config dosyasını yerine app.config dosyasını kullanmak istiyorum, sadece daha temiz görünüyor: Eğer böyle bir şey yapmak için
Log4Net normal çalışıyor mu? Sormamın sebebi, Log4Net ... – Faraday
'u yüklemenize gerek olup olmadığımızı bilmek istiyorum. Ayrıca, sınıflarımın her birini sınıflarım arasında kopyalamak/yapıştırmak için kullandığım her sınıfta yazmamızı sağlamak için: özel statik readonly ILog Logger = LogManager.GetLogger (MethodBase.GetCurrentMethod(). DeclaringType); – Faraday
normalde çalıştığı anlamına mı geliyor? :) Test projeme log4net referansını ekledim ve kodun geri kalanı burada yayınlandı, test testinde veya prj'de verilen hata mesajı yok. – panjo