public void Log_AllLevelsException_FileCreated() { // arrange Log4NetLogController controller = new Log4NetLogController( configXml ); FileInfo resultFile; Exception exception = new Exception( "This is just a test! No exception has been thrown." ); // act controller.Trace( this.loggerName, LogLevel.Debugging, "Debugging!", exception ); controller.Trace( this.loggerName, LogLevel.Error, "Error!", exception ); controller.Trace( this.loggerName, LogLevel.Fatal, "Fatal!", exception ); controller.Trace( this.loggerName, LogLevel.Information, "Information!", exception ); controller.Trace( this.loggerName, LogLevel.Warning, "Warning!", exception ); controller.Shutdown(); resultFile = new FileInfo( "NGin.Core.Test.log" ); // assert Assert.True( resultFile.Exists ); StreamReader reader = new StreamReader( "NGin.Core.Test.log" ); string content = reader.ReadToEnd(); Assert.IsTrue( content.Contains( "DEBUG" ) ); Assert.IsTrue( content.Contains( "WARN" ) ); Assert.IsTrue( content.Contains( "INFO" ) ); Assert.IsTrue( content.Contains( "ERROR" ) ); Assert.IsTrue( content.Contains( "FATAL" ) ); reader.Close(); }
public void Log_AllLevelsSeveralThreads_FileCreated() { // arrange Log4NetLogController controller = new Log4NetLogController( configXml ); FileInfo resultFile; Thread tOne = new Thread( delegate( object param ) { Thread.Sleep( 150 ); ( ( ILogController ) param ).Trace( this.loggerName, LogLevel.Debugging, "Debugging!" ); Thread.Sleep( 150 ); ( ( ILogController ) param ).Trace( this.loggerName, LogLevel.Information, "Information!" ); } ); Thread tTwo = new Thread( delegate( object param ) { Thread.Sleep( 150 ); ( ( ILogController ) param ).Trace( this.loggerName, LogLevel.Error, "Error!" ); Thread.Sleep( 150 ); ( ( ILogController ) param ).Trace( this.loggerName, LogLevel.Warning, "Warning!" ); } ); Thread tThree = new Thread( delegate( object param ) { Thread.Sleep( 150 ); ( ( ILogController ) param ).Trace( this.loggerName, LogLevel.Fatal, "Fatal!" ); } ); // act tOne.Start( controller ); tTwo.Start( controller ); tThree.Start( controller ); tOne.Join(); tTwo.Join(); tThree.Join(); controller.Shutdown(); resultFile = new FileInfo( "NGin.Core.Test.log" ); // assert Assert.True( resultFile.Exists ); StreamReader reader = new StreamReader( "NGin.Core.Test.log" ); string content = reader.ReadToEnd(); Assert.IsTrue( content.Contains( "DEBUG" ) ); Assert.IsTrue( content.Contains( "WARN" ) ); Assert.IsTrue( content.Contains( "INFO" ) ); Assert.IsTrue( content.Contains( "ERROR" ) ); Assert.IsTrue( content.Contains( "FATAL" ) ); reader.Close(); }