public void TestMessagesLogSizeLimit() { const string TextTestMessage = "Test message."; QuickFix.SessionID sessionID = new QuickFix.SessionID("FIX.4.2", "SENDERCOMP", "TARGETCOMP"); long fileSizeLimitBytes = 1024; int filesLimit = 2; log = new SerilogLog.SerilogLog(logPath, sessionID, fileSizeLimitBytes, filesLimit, fileSizeLimitBytes, filesLimit); string testMessage = TextTestMessage; int testMessageSize = Encoding.UTF8.GetByteCount($"2020-11-11 21:45:47.153 +02:00 : 00000: {TextTestMessage}\n"); testMessage = TextTestMessage; long writtenBytes = 0; long line = 0; long limitBytes = fileSizeLimitBytes * filesLimit; while (writtenBytes < limitBytes) { log.OnIncoming($"{++line:D5}: {testMessage}"); writtenBytes += testMessageSize; Debug.Print($"Written bytes: {writtenBytes}"); } Debug.Print($"Limit passed, writing over the limit"); for (int i = 0; i < 2; ++i) { log.OnOutgoing("Over size limit text!"); } long dirSize = DirectorySize(logPath); Debug.Print($"Calculated {dirSize} bytes for {logPath}"); Assert.IsTrue(dirSize <= limitBytes, $"Size {dirSize} unexpectedly exceeds limit {limitBytes}"); }
public void Teardown() { log?.Dispose(); log = null; if (Directory.Exists(logPath)) { Directory.Delete(logPath, true); } }