Logging
S# offers several graphical components for displaying logs: LogControl and Monitor.
When using the logging visual components, you need to use the GuiLogListenerlogger as a "listener". This logger provides streaming synchronization with the GUI when recording new LogMessage messages.
In order to implement the logging possibility in your own class, you need to implement the ILogReceiverinterface. An easier way is to inherit from the BaseLogReceiverclass, as shown in the Samples\Misc\SampleLoggingGitHub example:
private class TestSource : BaseLogReceiver
{
}
private readonly LogManager _logManager = new LogManager();
private readonly TestSource _testSource = new TestSource();
public MainWindow()
{
InitializeComponent();
// immediate flush
_logManager.FlushInterval = TimeSpan.FromMilliseconds(1);
// set test log source
_logManager.Sources.Add(_testSource);
// set .NET Trace system based source
_logManager.Sources.Add(new StockSharp.Logging.TraceSource());
// write logs into MainWindow
_logManager.Listeners.Add(new GuiLogListener(MonitorW));
// and file logs.txt
_logManager.Listeners.Add(new FileLogListener
{
FileName = "logs",
});
}