public void CanSplitFileWithTemplatedName() { var writer = new TextFileWriter { FileName = Path.Combine(Tmpdir, "${date}-${host}-${level}.log"), CustomFormat = "${Time} : ${Message}", Level = LogLevel.All }; var message1 = new LogMessage { Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1" }; writer.Write(message1); message1 = new LogMessage { Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1_2" }; writer.Write(message1); var message2 = new LogMessage { Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2" }; writer.Write(message2); message2 = new LogMessage { Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2_1" }; writer.Write(message2); Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log"))); Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log"))); var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log")); var seclog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log")); Console.WriteLine(fstlog); Console.WriteLine(seclog); Assert.AreEqual(@"2010-05-02 00:00:00 : message1 2010-05-02 00:00:00 : message1_2".LfOnly(), fstlog.Trim().LfOnly()); Assert.AreEqual(@"2010-05-03 00:00:00 : message2 2010-05-03 00:00:00 : message2_1".LfOnly(), seclog.Trim().LfOnly()); }
public void Write(String msg, params Object[] args) { if (FTextWriter != null) { FTextWriter.Write(msg, args); } }
public void WriteReadFile() { TextFileWriter writer = new TextFileWriter(path); writer.Write(content); TextFileReader reader = new TextFileReader(path); Assert.AreEqual(content, reader.GetString()); }
public void CanGenerateAdditionalFilesOnSizeChange() { var writer = new TextFileWriter { FileName = Path.Combine(Tmpdir, "my.log"), CustomFormat = "${Time} : ${Message}", Level = LogLevel.All, MaxSize = 0.5m, //500 байт }; var message1 = new LogMessage { Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "this is a message" }; for (var i = 0; i <= 10; i++) { writer.Write(message1); } message1.Message = "another message"; for (var i = 0; i <= 10; i++) { writer.Write(message1); } Assert.True(File.Exists(Path.Combine(Tmpdir, "0001.my.log"))); Assert.True(File.Exists(Path.Combine(Tmpdir, "0002.my.log"))); var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "0001.my.log")); var seclog = File.ReadAllText(Path.Combine(Tmpdir, "0002.my.log")); var size1 = new FileInfo(Path.Combine(Tmpdir, "0001.my.log")).Length; var size2 = new FileInfo(Path.Combine(Tmpdir, "0002.my.log")).Length; Console.WriteLine(fstlog); Console.WriteLine(seclog); Console.WriteLine(size1); Console.WriteLine(size2); Assert.LessOrEqual(519, size1); Assert.LessOrEqual(345, size2); }
public void TextFileWriter_WritesFileToDisk() { var path = "file.txt"; var encryptionService = new AesEncryptionService(); var textFileWriter = new TextFileWriter(path, true, encryptionService, Encoding.Unicode); textFileWriter.Write("Hello world!"); var fileExists = File.Exists(path); Assert.True(fileExists); }
public void CanGenerateAdditionalFilesOnSizeChange() { var writer = new TextFileWriter { FileName = Path.Combine(Tmpdir, "my.log"), CustomFormat = "${Time} : ${Message}", Level = LogLevel.All, MaxSize = 0.5m, //500 байт }; var message1 = new LogMessage {Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "this is a message"}; for (var i = 0; i <= 10; i++) { writer.Write(message1); } message1.Message = "another message"; for (var i = 0; i <= 10; i++) { writer.Write(message1); } Assert.True(File.Exists(Path.Combine(Tmpdir, "0001.my.log"))); Assert.True(File.Exists(Path.Combine(Tmpdir, "0002.my.log"))); var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "0001.my.log")); var seclog = File.ReadAllText(Path.Combine(Tmpdir, "0002.my.log")); var size1 = new FileInfo(Path.Combine(Tmpdir, "0001.my.log")).Length; var size2 = new FileInfo(Path.Combine(Tmpdir, "0002.my.log")).Length; Console.WriteLine(fstlog); Console.WriteLine(seclog); Console.WriteLine(size1); Console.WriteLine(size2); Assert.LessOrEqual(519, size1); Assert.LessOrEqual(345, size2); }
public void Evaluate(out OutAttrubute outputAttribute) { outputAttribute = new OutAttrubute(); try { outputAttribute.add("log", logFileName); sqlContext = new SQLContext(logWriter.Write); config = new ConfigHelper(inputParameter.ConfigExcelFilePath, logWriter.Write); config.Initilize(); inputData = new InputDataHelper(inputParameter.InputExcelFilePath, logWriter.Write); Dictionary <string, DataTable> baseData = inputData.GetBaseData(config.GetBaseDataObjectNames()); config.SetBaseDataObjectContext(baseData); config.ValidateBaseDataObjects(); //insert data in sql config.EvaluateComputedDataObjects(sqlContext); //validate computed data types config.ValidateComputedDataObjects(); var outputfile = Path.Combine(inputParameter.LogFolder, prefix + inputParameter.OutputFileName); outputAttribute.add("csv", outputfile); outputTextWriter = new TextFileWriter(outputfile); logWriter.Write(outputfile); outputTextWriter.Write(OutputMeasure.CsvHeader); config.WriteMeasureOutput(outputTextWriter); } catch (Exception ex) { logWriter.Write(ex.Message); } }
public void CanSplitFileWithTemplatedName() { var writer = new TextFileWriter { FileName = Path.Combine(Tmpdir, "${date}-${host}-${level}.log"), CustomFormat = "${Time} : ${Message}", Level = LogLevel.All }; var message1 = new LogMessage {Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1"}; writer.Write(message1); message1 = new LogMessage {Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1_2"}; writer.Write(message1); var message2 = new LogMessage {Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2"}; writer.Write(message2); message2 = new LogMessage {Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2_1"}; writer.Write(message2); Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log"))); Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log"))); var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log")); var seclog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log")); Console.WriteLine(fstlog); Console.WriteLine(seclog); Assert.AreEqual(@"2010-05-02 00:00:00 : message1 2010-05-02 00:00:00 : message1_2".LfOnly(), fstlog.Trim().LfOnly()); Assert.AreEqual(@"2010-05-03 00:00:00 : message2 2010-05-03 00:00:00 : message2_1".LfOnly(), seclog.Trim().LfOnly()); }
public void TextFileWriterWithNullBuffersize() { TextFileWriter writer = new TextFileWriter(path); writer.Write( new MemoryStream( Encoding.Default.GetBytes("text") ) , 0 ); }
public void TextFileWriterWithNullStream() { TextFileWriter writer = new TextFileWriter(path); writer.Write(null, 2); }
public void TextFileWriterWithNullBuffersize() { TextFileWriter writer = new TextFileWriter(path); writer.Write(new MemoryStream(Encoding.Default.GetBytes("text")), 0); }