public void RenderUsesDistinctRendererInstances() { Log4Net.Configure() .Render.Type <Int16>().Using(new Int16Renderer()) .Render.Type <Int32>().Using <Int16Renderer>() .Render.Type <Int64>().Using(typeof(Int16Renderer)) .Render.Type(typeof(Decimal)).Using(new Int16Renderer()) .Render.Type(typeof(Single)).Using(typeof(Int16Renderer)) .Render.Type(typeof(Double)).Using <Int16Renderer>() .ApplyConfiguration(); var repo = LogManager.GetRepository(); var int16Renderer = repo.RendererMap.Get(typeof(Int16)); var int32Renderer = repo.RendererMap.Get(typeof(Int32)); var int64Renderer = repo.RendererMap.Get(typeof(Int64)); var decimalRenderer = repo.RendererMap.Get(typeof(Decimal)); var singleRenderer = repo.RendererMap.Get(typeof(Single)); var doubleRenderer = repo.RendererMap.Get(typeof(Double)); Assert.That(int16Renderer, Is.Not.SameAs(int32Renderer)); Assert.That(int32Renderer, Is.Not.SameAs(int64Renderer)); Assert.That(int64Renderer, Is.Not.SameAs(decimalRenderer)); Assert.That(decimalRenderer, Is.Not.SameAs(singleRenderer)); Assert.That(singleRenderer, Is.Not.SameAs(doubleRenderer)); }
public void ApplyConfigurationSetsConfigured() { var repo = LogManager.GetRepository(); Assert.That(repo.Configured, Is.False); Log4Net.Configure().ApplyConfiguration(); Assert.That(repo.Configured, Is.True); }
public void ApplyConfigurationRaisesConfigurationChanged() { var changed = false; var repo = LogManager.GetRepository(); repo.ConfigurationChanged += (sender, args) => changed = true; Log4Net.Configure().ApplyConfiguration(); Assert.That(changed, Is.True); }
public void ApplyConfigurationResetsConfiguration() { var reset = false; var repo = LogManager.GetRepository(); repo.ConfigurationReset += (sender, args) => reset = true; Log4Net.Configure().ApplyConfiguration(); Assert.That(reset, Is.True); }
public void ThresholdAppliesRepositoryThreshold() { var repo = LogManager.GetRepository(); Log4Net.Configure() .Global.Threshold(Level.Notice) .ApplyConfiguration(); Assert.That(repo.Threshold, Is.EqualTo(Level.Notice)); }
public void NullRootLoggingLevelIsIgnored() { Log4Net.Configure() .Logging.Default(log => log.At(null)) .ApplyConfiguration(); var repo = (Hierarchy)LogManager.GetRepository(); Assert.That(repo.Root.Level, Is.EqualTo(Level.Debug)); }
public void RenderLambdaUsesActionRenderer() { Log4Net.Configure() .Render.Type <Int32>().Using((map, obj, writer) => { }) .ApplyConfiguration(); var repo = LogManager.GetRepository(); var int32Renderer = repo.RendererMap.Get(typeof(Int32)); Assert.That(int32Renderer, Is.Not.Null); Assert.That(int32Renderer.GetType().Name, Is.EqualTo("ActionRenderer")); }
public void CustomLock() { Log4Net.Configure() .Logging.Default(l => l.To.File(f => f.LockingWith <MyLock>())) .ApplyConfiguration(); var repo = LogManager.GetRepository(); var appenders = repo.GetAppenders(); var fileAppender = (FileAppender)appenders[0]; Assert.That(fileAppender.LockingModel, Is.TypeOf <MyLock>()); }
public void FileName() { Log4Net.Configure() .Logging.Default(l => l.To.File(f => f.Named(@"fileName"))) .ApplyConfiguration(); var repo = LogManager.GetRepository(); var appenders = repo.GetAppenders(); var fileAppender = (FileAppender)appenders[0]; Assert.That(fileAppender.File, Is.EqualTo(@"fileName")); }
public void RenderThrowsArgumentExceptionOnWrongType() { const string error = "Type {0} must implement IObjectRenderer to be configured as a renderer."; Assert.That(() => Log4Net.Configure() .Render.Type <Int32>().Using(typeof(Int32)) .ApplyConfiguration(), Throws.ArgumentException.With.Message.EqualTo(String.Format(error, typeof(Int32).FullName))); Assert.That(() => Log4Net.Configure() .Render.Type(typeof(Int64)).Using(typeof(Int64)) .ApplyConfiguration(), Throws.ArgumentException.With.Message.EqualTo(String.Format(error, typeof(Int64).FullName))); }
public void RenderThrowsArgumentNullExceptionOnNullObjectRenderer() { const string error = "Renderer cannot be null.\r\nParameter name: renderer"; Assert.That(() => Log4Net.Configure() .Render.Type <Int32>().Using((IObjectRenderer)null) .ApplyConfiguration(), Throws.Exception.TypeOf <ArgumentNullException>().With.Message.EqualTo(error)); Assert.That(() => Log4Net.Configure() .Render.Type(typeof(Int64)).Using((IObjectRenderer)null) .ApplyConfiguration(), Throws.Exception.TypeOf <ArgumentNullException>().With.Message.EqualTo(error)); }
public void ChildLoggingLevel() { Log4Net.Configure() .Logging.For <Int32>(log => log.At(Level.Warn)) .Logging.For(typeof(Int64), log => log.At(Level.Notice)) .Logging.For("Foo", log => log.At(Level.Alert)) .ApplyConfiguration(); var intLogger = (Logger)LogManager.GetLogger(typeof(Int32)).Logger; var longLogger = (Logger)LogManager.GetLogger(typeof(Int64)).Logger; var fooLogger = (Logger)LogManager.GetLogger("Foo").Logger; Assert.That(intLogger.Level, Is.EqualTo(Level.Warn)); Assert.That(longLogger.Level, Is.EqualTo(Level.Notice)); Assert.That(fooLogger.Level, Is.EqualTo(Level.Alert)); }
public void RootAppenderConfiguration() { var mockAppender = MockRepository.GenerateMock <IAppender>(); var mockDefinition = MockRepository.GenerateMock <IAppenderDefinition>(); mockDefinition.Stub(a => a.CreateAppender()).Return(mockAppender); Log4Net.Configure() .Logging.Default(log => log .At(Level.Verbose) .To.Appender(mockDefinition)) .ApplyConfiguration(); var repo = (Hierarchy)LogManager.GetRepository(); Assert.That(repo.Root.Appenders, Has.Count.EqualTo(1)); Assert.That(repo.Root.Appenders[0], Is.EqualTo(mockAppender)); }
public void RenderRegistersRenderer() { Log4Net.Configure() .Render.Type <Int16>().Using(new Int16Renderer()) .Render.Type <Int32>().Using <Int32Renderer>() .Render.Type <Int64>().Using(typeof(Int64Renderer)) .Render.Type(typeof(Decimal)).Using(new DecimalRenderer()) .Render.Type(typeof(Single)).Using(typeof(SingleRenderer)) .Render.Type(typeof(Double)).Using <DoubleRenderer>() .ApplyConfiguration(); var repo = LogManager.GetRepository(); Assert.That(repo.RendererMap.Get(typeof(Int16)), Is.TypeOf <Int16Renderer>()); Assert.That(repo.RendererMap.Get(typeof(Int32)), Is.TypeOf <Int32Renderer>()); Assert.That(repo.RendererMap.Get(typeof(Int64)), Is.TypeOf <Int64Renderer>()); Assert.That(repo.RendererMap.Get(typeof(Decimal)), Is.TypeOf <DecimalRenderer>()); Assert.That(repo.RendererMap.Get(typeof(Single)), Is.TypeOf <SingleRenderer>()); Assert.That(repo.RendererMap.Get(typeof(Double)), Is.TypeOf <DoubleRenderer>()); }
public void NullChildLoggingLevelAppliesRootLevel() { Log4Net.Configure() .Logging.Default(log => log.At(Level.Trace)) .Logging.For <Int32>(log => log.At(null)) .Logging.For(typeof(Int64), log => log.At(null)) .Logging.For("Foo", log => log.At(null)) .ApplyConfiguration(); var intLogger = (Logger)LogManager.GetLogger(typeof(Int32)).Logger; var longLogger = (Logger)LogManager.GetLogger(typeof(Int64)).Logger; var fooLogger = (Logger)LogManager.GetLogger("Foo").Logger; Assert.That(intLogger.Level, Is.Null); Assert.That(longLogger.Level, Is.Null); Assert.That(fooLogger.Level, Is.Null); Assert.That(intLogger.EffectiveLevel, Is.EqualTo(Level.Trace)); Assert.That(longLogger.EffectiveLevel, Is.EqualTo(Level.Trace)); Assert.That(fooLogger.EffectiveLevel, Is.EqualTo(Level.Trace)); }
public void ChildAppenderConfiguration() { var mockAppender = MockRepository.GenerateMock <IAppender>(); var mockDefinition = MockRepository.GenerateMock <IAppenderDefinition>(); mockDefinition.Stub(a => a.CreateAppender()).Return(mockAppender); Log4Net.Configure() .Logging.For <Int32>(log => log.To.Appender(mockDefinition)) .Logging.For(typeof(Int64), log => log.To.Appender(mockDefinition)) .Logging.For("Foo", log => log.To.Appender(mockDefinition)) .ApplyConfiguration(); var intLogger = (Logger)LogManager.GetLogger(typeof(Int32)).Logger; var longLogger = (Logger)LogManager.GetLogger(typeof(Int64)).Logger; var fooLogger = (Logger)LogManager.GetLogger("Foo").Logger; Assert.That(intLogger.Appenders, Has.Count.EqualTo(1)); Assert.That(intLogger.Appenders[0], Is.EqualTo(mockAppender)); Assert.That(longLogger.Appenders, Has.Count.EqualTo(1)); Assert.That(longLogger.Appenders[0], Is.EqualTo(mockAppender)); Assert.That(fooLogger.Appenders, Has.Count.EqualTo(1)); Assert.That(fooLogger.Appenders[0], Is.EqualTo(mockAppender)); }