11using Microsoft . Extensions . Configuration ;
22using Microsoft . Extensions . Logging ;
3- using NReco . Logging . File ;
4- using System . IO ;
53using System . Runtime . InteropServices ;
64using System . Runtime . Intrinsics . Arm ;
75using System . Runtime . Intrinsics . X86 ;
@@ -17,6 +15,9 @@ namespace TS.NET.Engine
1715 // By serialising the config-update/data-read it also allows for specific behaviours (like pausing acquisition on certain config updates) and ensuring a perfect match between sample-block & hardware configuration that created it.
1816 public class EngineManager
1917 {
18+ private readonly ILoggerFactory loggerFactory ;
19+ private readonly ILogger logger ;
20+
2021 private ThunderscopeSettings ? thunderscopeSettings = null ;
2122 private IThunderscope ? thunderscope = null ;
2223
@@ -28,6 +29,12 @@ public class EngineManager
2829
2930 public BlockingChannel < INotificationDto > ? UiNotifications ;
3031
32+ public EngineManager ( ILoggerFactory loggerFactory )
33+ {
34+ this . loggerFactory = loggerFactory ;
35+ logger = loggerFactory . CreateLogger ( nameof ( EngineManager ) ) ;
36+ }
37+
3138 public bool TryStart ( string configurationFile , string calibrationFile , string deviceSerial )
3239 {
3340 Console . CancelKeyPress += ( sender , e ) => { StopLibtslitex ( ) ; Environment . Exit ( 0 ) ; } ; // Handle Ctrl+C or Ctrl+Break event.
@@ -40,27 +47,9 @@ public bool TryStart(string configurationFile, string calibrationFile, string de
4047 // Commented out for now, more testing needed on Windows
4148 //using FileStream fs = new(lockFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
4249
43- IConfigurationBuilder configurationBuilder = new ConfigurationBuilder ( ) . AddJsonFile (
44- "thunderscope-appsettings.json"
45- ) ;
46- var configuration = configurationBuilder . Build ( ) ;
4750 thunderscopeSettings = ThunderscopeSettings . FromYamlFile ( configurationFile ) ;
4851 var thunderscopeCalibrationSettings = ThunderscopeCalibrationSettings . FromJsonFile ( calibrationFile ) ;
4952
50- var loggerFactory = LoggerFactory . Create ( configure =>
51- {
52- configure
53- . ClearProviders ( )
54- . AddConfiguration ( configuration . GetSection ( "Logging" ) )
55- . AddFile ( configuration . GetSection ( "Logging" ) )
56- . AddSimpleConsole ( options =>
57- {
58- options . SingleLine = true ;
59- options . TimestampFormat = "HH:mm:ss " ;
60- } ) ;
61- } ) ;
62- var logger = loggerFactory . CreateLogger ( "TS.NET.Engine" ) ;
63-
6453 if ( RuntimeInformation . ProcessArchitecture == Architecture . X86 || RuntimeInformation . ProcessArchitecture == Architecture . X64 )
6554 {
6655 if ( ! Avx2 . IsSupported )
@@ -172,7 +161,7 @@ public bool TryStart(string configurationFile, string calibrationFile, string de
172161
173162 startSemaphore . Wait ( ) ;
174163 processingThread = new ProcessingThread (
175- loggerFactory : loggerFactory ,
164+ logger : loggerFactory . CreateLogger ( nameof ( ProcessingThread ) ) ,
176165 settings : thunderscopeSettings ,
177166 hardwareConfig : thunderscope . GetConfiguration ( ) ,
178167 preProcessingPool : preProcessingPool ,
@@ -184,15 +173,15 @@ public bool TryStart(string configurationFile, string calibrationFile, string de
184173
185174 startSemaphore . Wait ( ) ;
186175 preProcessingThread = new PreProcessingThread (
187- loggerFactory : loggerFactory ,
176+ logger : loggerFactory . CreateLogger ( nameof ( PreProcessingThread ) ) ,
188177 settings : thunderscopeSettings ,
189178 hardwarePool : hardwarePool ,
190179 preProcessingPool : preProcessingPool ) ;
191180 preProcessingThread . Start ( startSemaphore ) ;
192181
193182 startSemaphore . Wait ( ) ;
194183 hardwareThread = new HardwareThread (
195- loggerFactory : loggerFactory ,
184+ logger : loggerFactory . CreateLogger ( nameof ( HardwareThread ) ) ,
196185 settings : thunderscopeSettings ,
197186 thunderscope : thunderscope ,
198187 hardwarePool : hardwarePool ,
@@ -201,7 +190,7 @@ public bool TryStart(string configurationFile, string calibrationFile, string de
201190
202191 startSemaphore . Wait ( ) ;
203192 scpiServer = new ScpiServer (
204- loggerFactory ,
193+ logger : loggerFactory . CreateLogger ( nameof ( ScpiServer ) ) ,
205194 thunderscopeSettings ,
206195 System . Net . IPAddress . Any ,
207196 5025 ,
@@ -213,7 +202,7 @@ public bool TryStart(string configurationFile, string calibrationFile, string de
213202 switch ( thunderscopeSettings . WaveformBufferReader )
214203 {
215204 case "DataServer" :
216- DataServer dataServer = new ( loggerFactory , thunderscopeSettings , System . Net . IPAddress . Any , 5026 , captureBuffer ) ;
205+ DataServer dataServer = new ( loggerFactory . CreateLogger ( nameof ( DataServer ) ) , thunderscopeSettings , System . Net . IPAddress . Any , 5026 , captureBuffer ) ;
217206 waveformBufferReader = dataServer ;
218207 break ;
219208 case "None" :
0 commit comments