public static void Main(string[] args) { ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); ILogger logger = loggerFactory.CreateLogger("ChannelsDemo"); var cts = new CancellationTokenSource(); logger.LogInformation("Starting Producer / Consumer demo"); var producerFactory = new ProducerFactory <char>( cts.Token, logger, GetWorkingDirectory(), (char c) => BitConverter.GetBytes(c)); var channel = new UnboundedChannelFacade <char>(); var producer = new ProducerWrapper <char>(producerFactory, cts.Token, channel); Task producerTask = producer.RunAsync(); RunLoop(channel, logger); cts.Cancel(); Console.WriteLine(); logger.LogInformation("Waiting for producer to shutdown"); producerTask.Wait(); logger.LogInformation("Finished. Exiting."); }
private static void Setup( out List <string> logLines, out IWriteBuffer <char> writeBuffer, out BlockingLoggingProducer blockingLoggingProducer, out ProducerWrapper <char> producer, CancellationTokenSource cts = null) { CancellationToken token = cts == null ? CancellationToken.None : cts.Token; logLines = new List <string>(); ILogger log = MemoryLog.Create(logLines); // use a regular logging producer unless an override is passed in var factory = new BlockingLoggingProducerFactory(log); blockingLoggingProducer = factory.Instance; var channel = new UnboundedChannelFacade <char>(); producer = new ProducerWrapper <char>(factory, token, channel); writeBuffer = channel; }