public static LoggerConfigurator CreateLogConfig(Options options) { var logConfig = new LoggerConfigurator(options.Verbose ? LogLevel.Debug : LogLevel.Info); if (Environment.UserInteractive) { logConfig.ConfigureForConsole(); } else { logConfig.AddTraceListener(); } var logger = logConfig.GetLogger(); if (!string.IsNullOrWhiteSpace(options.LogFile)) { if (Directory.Exists(Path.GetDirectoryName(options.LogFile))) { logConfig.ConfigureForFile(options.LogFile); } else { logger.Warn(string.Format("Failed to load log file. Path for {0} does not exist.", options.LogFile)); } } return(logConfig); }
public async Task WhenMultipleAdaptersAreConfigured_ResponsesAreOnlySentToTheOriginatingAdapter() { var logConfig = new LoggerConfigurator(LogLevel.Trace); logConfig.ConfigureForConsole(); var robot = new RobotBuilder(logConfig) .DisablePluginDiscovery() .DisableScriptDiscovery() .UseAdapter <StubAdapter>() .UseAdapter <StubAdapter2>() .UseBrain <StubBrain>() .Build(); robot.AutoLoadScripts = false; var adapter1 = robot.Adapters.Values.OfType <StubAdapter>().First(); var adapter2 = robot.Adapters.Values.OfType <StubAdapter2>().First(); robot.LoadScript <StubEchoScript>(); var expectedMessages = new[] { Tuple.Create("test1", "Hello Test 1"), Tuple.Create("test2", "Hello Test 2"), Tuple.Create("test3", "Hello Test 3") }; await robot.Run(); Console.WriteLine("Testing Adapter 1"); expectedMessages.ForEach(t => adapter1.SimulateMessage(t.Item1, "mmbot " + t.Item2)); var expectedMessagesValues = expectedMessages.Select(t => string.Concat(t.Item1, t.Item2)); Console.WriteLine("Expected:"); Console.WriteLine(string.Join(Environment.NewLine, expectedMessagesValues)); var actualMessagesValues = adapter1.Messages.Select(t => string.Concat(t.Item1.User.Name, t.Item2.FirstOrDefault())); Console.WriteLine("Actual:"); Console.WriteLine(string.Join(Environment.NewLine, actualMessagesValues)); Assert.True(expectedMessagesValues.SequenceEqual(actualMessagesValues)); Assert.Equal(0, adapter2.Messages.Count()); Console.WriteLine("Testing Adapter 2"); expectedMessages.ForEach(t => adapter2.SimulateMessage(t.Item1, "mmbot " + t.Item2)); Console.WriteLine("Expected:"); Console.WriteLine(string.Join(Environment.NewLine, expectedMessagesValues)); actualMessagesValues = adapter2.Messages.Select(t => string.Concat(t.Item1.User.Name, t.Item2.FirstOrDefault())); Console.WriteLine("Actual:"); Console.WriteLine(string.Join(Environment.NewLine, actualMessagesValues)); Assert.True(expectedMessagesValues.SequenceEqual(actualMessagesValues)); Assert.Equal(3, adapter1.Messages.Count()); }