public void Test2() { var now = new DateTime(2015, 2, 1); StreamTextWriterFactory writerFactory = new StreamTextWriterFactory(new DayLogPathFactory()); TextLogger logger = new TextLogger(writerFactory, new LogDescriptor()); writerFactory.NowGetter = () => now; logger.Write(new LogItem() { Time = now, Message = "测试内容。", Type = LogType.Info }); System.Threading.Thread.Sleep(1001); var path = GA.FullPath(LogFolder, "2015年02月", "01.log"); try { Assert.Equal(now.ToString("HH:mm:ss.ffff") + " [消息] 测试内容。\r\n", GA.IO.ShareReadAllText(path, Encoding.UTF8)); } catch (UnauthorizedAccessException) { //.... } }
public void Test1() { var now = new DateTime(2015, 1, 1); const string logText = "abcdefg"; StreamTextWriterFactory writerFactory = new StreamTextWriterFactory(new DayLogPathFactory()); writerFactory.NowGetter = () => now; writerFactory.Process(writer => { writer.Write(logText); }); var path = GA.FullPath(LogFolder, "2015年01月", "01.log"); Assert.Equal(logText, GA.IO.ShareReadAllText(path, Encoding.UTF8)); }
public void Test2() { var now = new DateTime(2015, 2, 1); StreamTextWriterFactory writerFactory = new StreamTextWriterFactory(new DayLogPathFactory()); TextLogger logger = new TextLogger(writerFactory, new LogDescriptor()); writerFactory.NowGetter = () => now; logger.Write(new LogItem() { Time = now, Message = "测试内容。", Type = LogType.Info }); System.Threading.Thread.Sleep(1001); var path = GA.FullPath(LogFolder, "2015年02月", "01.log"); Assert.Equal(now.ToString("HH:mm:ss.ffff") + " [消息] 测试内容。\r\n", GA.IO.ShareReadAllText(path, Encoding.UTF8)); }