Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RollingFileLogFactory to support logging in separate files, all… #848

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions QuickFIXn/Logger/FileLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ public class FileLog : ILog
/// path separator (i.e. "/" will become "\" on windows, else "\" will become "/" on all other platforms)
/// </param>
/// <param name="sessionId"></param>
public FileLog(string fileLogPath, SessionID sessionId)
public FileLog(string fileLogPath, SessionID sessionId) : this(fileLogPath, sessionId, false)
{
}
/// <summary>
///
/// </summary>
/// <param name="createDailyLogFile"></param>
public FileLog(string fileLogPath, SessionID sessionId, bool createDailyLogFile)
{
string prefix = Prefix(sessionId);

Expand All @@ -34,8 +41,17 @@ public FileLog(string fileLogPath, SessionID sessionId)
if (!System.IO.Directory.Exists(normalizedPath))
System.IO.Directory.CreateDirectory(normalizedPath);

_messageLogFileName = System.IO.Path.Combine(normalizedPath, prefix + ".messages.current.log");
_eventLogFileName = System.IO.Path.Combine(normalizedPath, prefix + ".event.current.log");
if (createDailyLogFile)
{
string currentDate = DateTime.UtcNow.ToString("yyyyMMdd");
_messageLogFileName = System.IO.Path.Combine(fileLogPath, $"{currentDate}.{prefix}.messages.log");
_eventLogFileName = System.IO.Path.Combine(fileLogPath, $"{currentDate}.{prefix}.event.log");
}
else
{
_messageLogFileName = System.IO.Path.Combine(normalizedPath, prefix + ".messages.current.log");
_eventLogFileName = System.IO.Path.Combine(normalizedPath, prefix + ".event.current.log");
}

_messageLog = new System.IO.StreamWriter(_messageLogFileName, true);
_eventLog = new System.IO.StreamWriter(_eventLogFileName, true);
Expand Down
35 changes: 35 additions & 0 deletions QuickFIXn/Logger/RollingFileLogFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuickFix.Logger
{
/// <summary>
/// Creates a message store that stores messages in a file separated by date
/// </summary>
public class RollingFileLogFactory : ILogFactory
{
private readonly SessionSettings _settings;

#region LogFactory Members

public RollingFileLogFactory(SessionSettings settings)
{
_settings = settings;
}

/// <summary>
/// Creates a file-based message store separated by date
/// </summary>
/// <param name="sessionId">session ID for the message store</param>
/// <returns></returns>
public ILog Create(SessionID sessionId)
{
return new FileLog(_settings.Get(sessionId).GetString(SessionSettings.FILE_LOG_PATH), sessionId,true);
}

#endregion
}
}