none
Creating a Logger with multiple channels using tpl dataflow RRS feed

  • Question

  • Hey, 
    Im trying to create a logger that can send the log messages to multiple channels at once, each channel has a Write method that deliver the Log to the desired LogSite  e.g Syslog, WindowsEventViewer etc.

    What i did is creating an ActionBlock for each channel, and used a BroadcastBlock as the main receiver, that transfer the log to all the ActionBlocks (all channels).

    Something like this:
    ************************************
    Broadcast = new BroadcastBlock<BaseLogMessage>(log => log);
    SysLogBlock = new ActionBlock<BaseLogMessage>(log => SysLog.Instance.Write(log));
    EmailLogBlock = new ActionBlock<BaseLogMessage>(log => EmailLog.Instance.Write(log));
    WindowsEventLogBlock = new ActionBlock<BaseLogMessage>(log => WindowsEventLog.Instance.Write(log));

    Broadcast.LinkTo(SysLogBlock);
    Broadcast.LinkTo(EmailLogBlock);
    Broadcast.LinkTo(WindowsEventLogBlock);
    ************************************
    Then when i want to Log i call:
    Broadcast.Post(BaseLogMessage("the log message"));

    This *seems* to work fine, so just in case im in a wrong direction here please let me know.
    Now, i noticed that when i have LOTS of logs, some of them are getting lost, im guessing that the problem is with the buffer size of the Blocks, 
    so if a block reaches its full capacity, it will ignore the incoming log calls.

    How can i improve this so that i will not get any Logs get lost?
    Is inserting a BufferBlock should fix it? but where in the hierarchy should i insert it? 
    Does each ActionBlock (channel) needs to have its own buffer ahead of it? cause maybe(probably) their execution times are different.
    Last but not least, how can i tell the ActionBlocks (channels) to grab the next log from the buffer?

    Any help or direction would be greatly appreciated!

    Roy.

    Tuesday, April 26, 2016 5:22 PM