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

Move to Microsoft.Extensions.Logging #899

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d3d3c9e
Migrate to Microsoft.Extensions.Logging
jkulubya Nov 24, 2024
e130f42
Mark old logger obsolete
jkulubya Nov 27, 2024
581d651
Make transitional classes obsolete
jkulubya Nov 27, 2024
ed7f591
Add message type to log scope
jkulubya Nov 27, 2024
57d7ae3
Forward to single constructor
jkulubya Dec 10, 2024
d6b4535
Delete nulllogger and nullloggerprovider
jkulubya Dec 10, 2024
3235611
Relax MEL version requirements to allow v6 to 8
jkulubya Dec 10, 2024
f66e557
Undo public API change in Send(string message)
jkulubya Dec 10, 2024
67e7fee
Merge transitional classes into existing log implementations
jkulubya Dec 11, 2024
b3ad725
Remove stray log
jkulubya Dec 12, 2024
231b790
Use NullLoggerProvider.Instance instead of constructing one
jkulubya Dec 12, 2024
e21307a
Use delegate overload for GetOrAdd
jkulubya Dec 12, 2024
2ed24b5
Ignore nullability error while implementing ILogger.BeginScope
jkulubya Dec 12, 2024
9ad26d3
Ignore nullability error while implementing ILogger.BeginScope
jkulubya Dec 12, 2024
40f336e
Make sure owned logging classes are disposed.
jkulubya Dec 12, 2024
841fcee
Naming
jkulubya Dec 12, 2024
ab4737e
Set min version of MEL.Abstractions to v6 and no upper limit
jkulubya Dec 13, 2024
4590b62
Use LoggerFactory constructor that disposes ILoggerProviders
jkulubya Dec 15, 2024
252bb00
Merge branch 'master' into ilogger
jkulubya Jan 5, 2025
283a3b8
Set ILogger.BeginScope type to match net6 and not later. Clears nulla…
jkulubya Jan 5, 2025
05c650b
Make NonSessionFileLogger obsolete
jkulubya Jan 5, 2025
d145d73
Refactor to set proper categories
jkulubya Jan 9, 2025
0f52aa0
Make log levels make sense
jkulubya Jan 9, 2025
cc7cc9e
Add serilog example project
jkulubya Jan 9, 2025
44f94ad
Use lock over normal dictionary for session loggers
jkulubya Jan 18, 2025
1574490
Roll log files hourly not by the minute
jkulubya Jan 18, 2025
1959f9d
Cleanup
jkulubya Jan 18, 2025
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
4 changes: 3 additions & 1 deletion AcceptanceTest/ATApplication.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using QuickFix;
using QuickFix.Fields;

Expand Down Expand Up @@ -182,7 +183,8 @@ public void FromApp(Message message, SessionID sessionId)
}
catch (System.Exception e)
{
Session.LookupSession(sessionId)?.Log.OnEvent($"Exception during FromApp: {e}\n while processing msg ({message})");
Session.LookupSession(sessionId)?.Log.Log(LogLevel.Error, e,
"Exception during FromApp: {Error}\n while processing msg ({Message})", e, message);
}
}

Expand Down
1 change: 1 addition & 0 deletions AcceptanceTest/AcceptanceTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Examples/Executor/Examples.Executor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
</ItemGroup>

</Project>
12 changes: 8 additions & 4 deletions Examples/Executor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Microsoft.Extensions.Logging;
using QuickFix;
using QuickFix.Logger;
using QuickFix.Store;

namespace Executor
Expand All @@ -27,9 +27,13 @@ static void Main(string[] args)
SessionSettings settings = new SessionSettings(args[0]);
IApplication executorApp = new Executor();
IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
ILogFactory logFactory = new ScreenLogFactory(settings);
//ILogFactory logFactory = new FileLogFactory(settings);
ThreadedSocketAcceptor acceptor = new ThreadedSocketAcceptor(executorApp, storeFactory, settings, logFactory);
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.SetMinimumLevel(LogLevel.Trace);
builder.AddConsole();
});
ThreadedSocketAcceptor acceptor =
new ThreadedSocketAcceptor(executorApp, storeFactory, settings, loggerFactory);
HttpServer srv = new HttpServer(HttpServerPrefix, settings);

acceptor.Start();
Expand Down
5 changes: 5 additions & 0 deletions Examples/SimpleAcceptor/Examples.SimpleAcceptor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
</ItemGroup>

</Project>
9 changes: 6 additions & 3 deletions Examples/SimpleAcceptor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Microsoft.Extensions.Logging;
using QuickFix;
using QuickFix.Logger;
using QuickFix.Store;

namespace SimpleAcceptor
Expand Down Expand Up @@ -30,8 +30,11 @@ static void Main(string[] args)
SessionSettings settings = new SessionSettings(args[0]);
IApplication app = new SimpleAcceptorApp();
IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
ILogFactory logFactory = new FileLogFactory(settings);
IAcceptor acceptor = new ThreadedSocketAcceptor(app, storeFactory, settings, logFactory);
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
});
IAcceptor acceptor = new ThreadedSocketAcceptor(app, storeFactory, settings, loggerFactory);

acceptor.Start();
Console.WriteLine("press <enter> to quit");
Expand Down
6 changes: 6 additions & 0 deletions Examples/Standalone/SerilogLog/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SerilogLog;

public class AppSettings
{
public required string ConfigFilePath { get; set; }
}
60 changes: 60 additions & 0 deletions Examples/Standalone/SerilogLog/FixBackgroundService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Microsoft.Extensions.Options;
using QuickFix;
using QuickFix.Store;
using QuickFix.Transport;

namespace SerilogLog;

public class FixBackgroundService(IOptions<AppSettings> appSettings, ILoggerFactory loggerFactory) : IHostedService, IApplication
{
private SocketInitiator? _initiator;

public Task StartAsync(CancellationToken cancellationToken)
{
var settings = new SessionSettings(appSettings.Value.ConfigFilePath);

var storeFactory = new FileStoreFactory(settings);
_initiator = new SocketInitiator(
this,
storeFactory,
settings,
loggerFactory);

_initiator.Start();
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
_initiator?.Stop();
return Task.CompletedTask;
}

public void ToAdmin(Message message, SessionID sessionId)
{
}

public void FromAdmin(Message message, SessionID sessionId)
{
}

public void ToApp(Message message, SessionID sessionId)
{
}

public void FromApp(Message message, SessionID sessionId)
{
}

public void OnCreate(SessionID sessionId)
{
}

public void OnLogout(SessionID sessionId)
{
}

public void OnLogon(SessionID sessionId)
{
}
}
74 changes: 74 additions & 0 deletions Examples/Standalone/SerilogLog/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Serilog;
using Serilog.Core;
using Serilog.Filters;

namespace SerilogLog;

class Program
{
static async Task Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Debug()
.WriteTo.Console()
.WriteTo.Logger(l => l
.Filter
.ByIncludingOnly(Matching.FromSource("QuickFix.SessionLogs"))
.Filter
.ByIncludingOnly(Matching.WithProperty("MessageType"))
.WriteTo.Map(Constants.SourceContextPropertyName, "", (source, lc) =>
{
var fileName = GetSessionIdFromSourceContext(source);
lc.File($"log/{fileName}.messages.log", rollingInterval: RollingInterval.Minute, outputTemplate:"{Message:lj}{NewLine}");
})
)
.WriteTo.Logger(l => l
.Filter
.ByIncludingOnly(Matching.FromSource("QuickFix.SessionLogs"))
.Filter
.ByExcluding(Matching.WithProperty("MessageType"))
.WriteTo.Map(Constants.SourceContextPropertyName, "", (source, lc) =>
{
var fileName = GetSessionIdFromSourceContext(source);
lc.File($"log/{fileName}.event.log", rollingInterval: RollingInterval.Minute, outputTemplate:"{Message:lj}{NewLine}");
})
)
.WriteTo.Logger(l => l
.Filter
.ByIncludingOnly(Matching.FromSource("QuickFix"))
.Filter
.ByExcluding(Matching.FromSource("QuickFix.SessionLogs"))
.WriteTo.File("log/Non-Session-Log.event.current.log")
)
.CreateLogger();

try
{
Log.Information("Starting host");

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<FixBackgroundService>();
builder.Services.AddSerilog();
builder.Services.Configure<AppSettings>(builder.Configuration);
var app = builder.Build();

await app.RunAsync();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
await Log.CloseAndFlushAsync();
}
}

private static string GetSessionIdFromSourceContext(string sourceContext)
{
// Log source is "QuickFix.SessionLogs.<session-id>", this returns <session-id>
var i = sourceContext.IndexOf('.', sourceContext.IndexOf('.') + 1) + 1;
return sourceContext[i..];
}
}
35 changes: 0 additions & 35 deletions Examples/Standalone/SerilogLog/README.md

This file was deleted.

33 changes: 33 additions & 0 deletions Examples/Standalone/SerilogLog/Serilog.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[DEFAULT]
ConnectionType=initiator
ReconnectInterval=2
FileStorePath=store
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=Y
SocketConnectHost=127.0.0.1
SocketConnectPort=5001
SocketIgnoreProxy=Y
ResetOnDisconnect=Y
FileLogPath=log
LogoutTimeout=5
ResetOnLogon=Y
HeartBtInt=10

[SESSION]
BeginString=FIX.4.0
SenderCompID=CLIENT1
TargetCompID=EXECUTOR
DataDictionary=../../../spec/fix/FIX40.xml

[SESSION]
BeginString=FIX.4.4
SenderCompID=CLIENT1
TargetCompID=EXECUTOR
DataDictionary=../../../spec/fix/FIX44.xml

[SESSION]
BeginString=FIX.4.4
SenderCompID=CLIENT2
TargetCompID=EXECUTOR
DataDictionary=../../../spec/fix/FIX44.xml
Loading
Loading