[MethodImpl(MethodImplOptions.NoInlining)] // Disable inlining since logging is off by default, and we want to allow the public method to be inlined private void WriteLineImpl(string line) { string fullLine = String.Format(CultureInfo.CurrentCulture, "{2}: ({0}) {1}", (int)(DateTime.Now - s_initTime).TotalMilliseconds, line, _id); s_logger?.WriteLine(fullLine); #if DEBUG Debug.WriteLine("MS_MIDebug: " + fullLine); #endif }
public void TestHostLoggerImportantArea() { var lines = LogInput.Split(new[] { "\r\n" }, StringSplitOptions.None); var output = new AccumulationLogger(); var logger = new HostLogger(output, HostLogMode.AllMessages); var config = new ManualConfig(); config.Add(logger); using (HostLogger.BeginLogImportant(config)) { foreach (var line in lines) { logger.WriteLine(line); } Assert.AreEqual(output.GetLog(), LogInput + "\r\n"); output = new AccumulationLogger(); logger = new HostLogger(output, HostLogMode.AllMessages); foreach (var line in lines) { logger.WriteLineError(line); } Assert.AreEqual(output.GetLog(), LogInput + "\r\n"); output = new AccumulationLogger(); logger = new HostLogger(output, HostLogMode.AllMessages); LogMessages(logger); // ReSharper disable once StringLiteralTypo const string Expected = @"ABCDEFGH TST0 // !TST1 TST2 // !<-- TST3 // !<-- TST4 TST5 // !--> TST6 // !--> TST7 TST8 // !TST9 TST10 "; Assert.AreEqual(output.GetLog(), Expected); } }
public void TestHostLoggerPrefixedOrErrors() { var lines = LogInput.Split(new[] { "\r\n" }, StringSplitOptions.None); var output = new AccumulationLogger(); var logger = new HostLogger(output, HostLogMode.PrefixedOrErrors); foreach (var line in lines) { logger.WriteLine(line); } Assert.AreEqual(output.GetLog(), PrefixedLogOutput); output = new AccumulationLogger(); logger = new HostLogger(output, HostLogMode.PrefixedOrErrors); foreach (var line in lines) { logger.WriteLineError(line); } Assert.AreEqual(output.GetLog(), LogInput + "\r\n"); output = new AccumulationLogger(); logger = new HostLogger(output, HostLogMode.PrefixedOrErrors); LogMessages(logger); const string Expected = @"AH TST0 // !TST1 // !<-- TST3 // !<-- TST4 TST5 // !--> TST6 // !--> "; Assert.AreEqual(output.GetLog(), Expected); }