Using log4net with QuickFix

View: New views
1 Messages — Rating Filter:   Alert me  

Using log4net with QuickFix

by Cormac Miller :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

if anyone is interested...

Classes that use log4net:

    public class Log4netLogFactory : QuickFix.LogFactory
    {
        public Log create()
        {
            return new Log4netLog();
        }

        public Log create(SessionID id)
        {
            return new Log4netLog();
        }
    }

    public class Log4netLog: QuickFix.Log
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger("Fix");

        public Log4netLog()
        {
        }

        public void onIncoming(String text)
        {
            log.InfoFormat("onIncoming: {0}", text);
        }

        public void onOutgoing(String text)
        {
            log.InfoFormat("onOutgoing: {0}", text);
        }

        public void onEvent(String text)
        {
            log.InfoFormat("onEvent: {0}", text);
        }

        public void clear()
        {
        }
    }

Create this Log instead of the usual file log:
                Log4netLogFactory logFactory = new Log4netLogFactory();
                initiator = new SocketInitiator(application,
                                                 storeFactory,
                                                 settings,
                                                 logFactory /*optional*/,
                                                 messageFactory);

And you can create a separate appender so the FIX messages don't overrun your application logfile:
        <!-- FIX gets its own appender so prevent it inheriting from root -->
        <logger name="Fix" additivity="false">
            <appender-ref ref="FixFileAppender" />
            <level value="debug" />
        </logger>