Question

How can I disable all of Quickfix/n's log and file factories? I want to handle all logging and message sending myself because I do not like the way how Quickfix sources log messages, meaning I want to decide when and how logging messages originate. Is there a way to completely disable any screen based or file based logging?

Thanks

Was it helpful?

Solution

There should be a NullLogFactory, but I don't currently see one, and I'm kind of confused why not. I thought there was one. (If you didn't know, I maintain QF/n.)

But you can create one like so:

public class NullLogFactory : ILogFactory
{
    SessionSettings settings_;

    #region LogFactory Members

    public NullLogFactory(SessionSettings settings)
    {}

    public ILog Create(SessionID sessionID)
    {
        return new QuickFix.NullLog();
    }

    #endregion
}

The next QF/n release will contain a null factory or something to fill that gap.

OTHER TIPS

Old question but possibly of use to somebody that searches for this.

If you want to make it easier to enable/disable logging I think it is much better to set a value in the app.config file and process it in the socket initiator class as such:

App.config

   <appSettings>
    <add key="LogMessages" value="false"/>
   </appSettings>

Application Code

bool logMessages = Convert.ToBoolean(ConfigurationManager.AppSettings["LogMessages"]);


try
{
    SocketInitiator initiator;
    QuickFix.SessionSettings settings = new QuickFix.SessionSettings(file);
    MessageProcessor application = new MessageProcessor();
    QuickFix.IMessageStoreFactory storeFactory = new QuickFix.FileStoreFactory(settings);
    QuickFix.ILogFactory logFactory = new QuickFix.FileLogFactory(settings);

    if (!logMessages)
        {
            initiator = new QuickFix.Transport.SocketInitiator(application, storeFactory, settings);
        }
        else
        {
            initiator = new QuickFix.Transport.SocketInitiator(application, storeFactory, settings, logFactory);
        }


    application.MyInitiator = initiator;

    initiator.Start();
    while (!initiator.IsLoggedOn)
    {
        //wait until the initiator has logged on
    }
    //do stuff
}
catch
{// exception handling code}

This question is an old one but hope this answer will help if anyone have the same issue as I did not find any related question.

According to the Quickfix Configuration, default value of FileLogPath in your configuration file is '-'. Therefore, remove or comment the FileLogPath setting from your configuration file.

When you create the socket initiator instance, you have 3 overloads by Quickfix SocketInitiator class as mentioned bellow.

public SocketInitiator(IApplication application, IMessageStoreFactory storeFactory, SessionSettings settings);
public SocketInitiator(IApplication application, IMessageStoreFactory storeFactory, SessionSettings settings, ILogFactory logFactory);
public SocketInitiator(IApplication application, IMessageStoreFactory storeFactory, SessionSettings settings, ILogFactory logFactory, IMessageFactory messageFactory);

We need to use the first one as we need to switch off the quickfix logs.

Sample code segment is mentioned bellow

SessionSettings settings = new("your-config.cfg");
IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
SocketInitiator initiator = new(_application, storeFactory, settings);

Afterwith, you can implement different logging mechanism to handle your logs. For example, Serilog

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top