Skip to content

Commit

Permalink
Added composite logging
Browse files Browse the repository at this point in the history
Allows use of multiple logging factories (e.g. console and file)
  • Loading branch information
Shay Rojansky committed Mar 27, 2013
1 parent 0abd154 commit 682a1f9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
40 changes: 40 additions & 0 deletions QuickFIXn/CompositeLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

namespace QuickFix
{
/// <summary>
/// File log implementation
/// </summary>
internal class CompositeLog : ILog
{
private ILog[] logs_;

public CompositeLog(ILog[] logs)
{
logs_ = logs;
}

public void Clear()
{
foreach (var log in logs_)
log.Clear();
}

public void OnIncoming(string msg)
{
foreach (var log in logs_)
log.OnIncoming(msg);
}

public void OnOutgoing(string msg)
{
foreach (var log in logs_)
log.OnOutgoing(msg);
}

public void OnEvent(string s)
{
foreach (var log in logs_)
log.OnEvent(s);
}
}
}
28 changes: 28 additions & 0 deletions QuickFIXn/CompositeLogFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Linq;

namespace QuickFix
{
/// <summary>
/// Allows multiple log factories to be used with QuickFIX/N. For example, you could log events to the console and also log all events and messages to a file.
/// </summary>
public class CompositeLogFactory : ILogFactory
{
private ILogFactory[] factories_;

public CompositeLogFactory(ILogFactory[] factories)
{
factories_ = factories;
}

/// <summary>
/// Creates a composite log
/// </summary>
/// <param name="sessionID">session ID for the message store</param>
/// <returns></returns>
public ILog Create(SessionID sessionID)
{
return new CompositeLog(factories_.Select(f => f.Create(sessionID)).ToArray());
}
}
}
2 changes: 2 additions & 0 deletions QuickFIXn/QuickFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CompositeLogFactory.cs" />
<Compile Include="CompositeLog.cs" />
<Compile Include="DataDictionary\IFieldMapSpec.cs" />
<Compile Include="DataDictionary\IGroupSpec.cs" />
<Compile Include="IAcceptor.cs" />
Expand Down

0 comments on commit 682a1f9

Please sign in to comment.