Click or drag to resize

Strategy logging

The Strategy class implements the ILogSource interface. Therefore, the strategies can be passed to the LogManagerSources, and all of its messages will automatically get to the LogManagerListeners.

Prerequisites

Logging in to test file

  1. First, you need to create the special manager:

    C#
    var logManager = new LogManager();
  2. Then you need to create a file logger, passing to it the name of the file and to add it to the LogManagerListeners:

    C#
    var fileListener = new FileLogListener("{0}_{1:00}_{2:00}.txt".Put(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
    logManager.Listeners.Add(fileListener);
  3. For logging messages, you need to add a strategy to the LogManagerSources:

    C#
    logManager.Sources.Add(lkohSmaStrategy);
  4. After adding strategy to the logging manager all of its messages will be recorded to file.

Sound playback

  1. Creating a logger and passing the name of the sound file in it:

    C#
    var soundListener = new SoundLogListener("error.mp3");
    
    logManager.Listeners.Add(soundListener);
    logManager.Sources.Add(lkohSmaStrategy);
  2. Setting the filter in the sound playback only when the type of messages is LogLevelsError:

    C#
    soundListener.Filters.Add(msg => msg.Level == LogLevels.Error);

Email sending

  1. The logger creating and passing to it sent letters parameters:

    C#
    var emailListener = new EmailLogListener("from@stocksharp.com", "to@stocksharp.com");
    
    logManager.Listeners.Add(emailListener);
    logManager.Sources.Add(lkohSmaStrategy);
  2. Setting the filter on the sending of messages of LogLevelsError and LogLevelsWarning types:

    C#
    emailListener.Filters.Add(msg => msg.Level == LogLevels.Error);
    emailListener.Filters.Add(msg => msg.Level == LogLevels.Warning);

Logging in to the LogWindow

  1. The GuiLogListener logger creating:

    C#
    // each strategy will have they own windows
    var guiListener = new GuiLogListener();
    
    logManager.Listeners.Add(guiListener);
    logManager.Sources.Add(lkohSmaStrategy);
  2. Here is the log window when orders quoting strategy working (Quoting):

    Логирование стратегий.
See Also