public AdvancedConsoleLogger(string name, Func <string, LogLevel, bool> filter, IReadonlyLoggerSettings settings) { if (name == null) { throw new ArgumentNullException(nameof(name)); } FullName = name; //class name without namespace ShortName = StripNamespace(name); Filter = filter ?? ((category, logLevel) => true); Settings = settings; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console = new WindowsLogConsole(); } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); } TimestampProvider = new TimestampProvider(new DateTimeProvider()); }
public void NotCallingFlush_DoesNotWriteData_ToSystemConsole() { // Arrange var systemConsole = new TestAnsiSystemConsole(); var console = new AnsiLogConsole(systemConsole); var message = "Request received"; var expectedMessage = message + Environment.NewLine; // Act console.WriteLine(message, background: null, foreground: null); // Assert Assert.Null(systemConsole.Message); }
public void WritesMessage_WithoutEscapeCodes_AndNoForegroundOrBackgroundColorsSpecified() { // Arrange var systemConsole = new TestAnsiSystemConsole(); var console = new AnsiLogConsole(systemConsole); var message = "Request received"; var expectedMessage = message + Environment.NewLine; // Act console.WriteLine(message, background: null, foreground: null); console.Flush(); // Assert Assert.Equal(expectedMessage, systemConsole.Message); }
public void DoesNotAddNewLine() { // Arrange var systemConsole = new TestAnsiSystemConsole(); var console = new AnsiLogConsole(systemConsole); var message = "Request received"; var expectedMessage = message; // Act console.Write(message, background: null, foreground: null); console.Flush(); // Assert Assert.Equal(expectedMessage, systemConsole.Message); }
public CustomConsoleLogger(string name, Func <string, LogLevel, bool> filter, bool includeScopes, ConsoleLoggerProcessor loggerProcessor) { Name = name ?? throw new ArgumentNullException(nameof(name)); Filter = filter ?? ((category, logLevel) => true); IncludeScopes = includeScopes; _queueProcessor = loggerProcessor; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console = new WindowsLogConsole(); } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); } }
public void WritesMessage_WithForegroundEscapeCode_AndNoBackgroundColorSpecified() { // Arrange var systemConsole = new TestAnsiSystemConsole(); var console = new AnsiLogConsole(systemConsole); var message = "Request received"; var expectedMessage = GetForegroundColorEscapeCode(ConsoleColor.DarkGreen) + message + "\x1B[39m\x1B[22m"; //resets foreground color // Act console.WriteLine(message, background: null, foreground: ConsoleColor.DarkGreen); console.Flush(); // Assert Assert.Equal(expectedMessage + Environment.NewLine, systemConsole.Message); }
public void CallingFlush_ClearsData_FromOutputBuilder() { // Arrange var systemConsole = new TestAnsiSystemConsole(); var console = new AnsiLogConsole(systemConsole); var message = "Request received"; var expectedMessage = message + Environment.NewLine; // Act console.WriteLine(message, background: null, foreground: null); console.Flush(); console.WriteLine(message, background: null, foreground: null); console.Flush(); // Assert Assert.Equal(expectedMessage, systemConsole.Message); }
public ConsoleLogger(string name, Func <string, LogLevel, bool> filter, bool includeScopes) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Filter = filter ?? ((category, logLevel) => true); IncludeScopes = includeScopes; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console = new WindowsLogConsole(); } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); } }
public void WriteMessage_InOrder_WhenBothForegroundOrBackgroundColorsSpecified() { // Arrange var systemConsole = new TestAnsiSystemConsole(); var console = new AnsiLogConsole(systemConsole); var message = "Request received"; var expectedMessage = GetBackgroundColorEscapeCode(ConsoleColor.Red) + GetForegroundColorEscapeCode(ConsoleColor.DarkGreen) + "Request received" + "\x1B[39m\x1B[22m" //resets foreground color + "\x1B[49m" //resets background color + Environment.NewLine; // Act console.WriteLine(message, background: ConsoleColor.Red, foreground: ConsoleColor.DarkGreen); console.Flush(); // Assert Assert.Equal(expectedMessage, systemConsole.Message); }
internal CustomerConsoleLogger(string name, Func <string, LogLevel, bool> filter, IExternalScopeProvider scopeProvider, ConsoleLoggerProcessor loggerProcessor) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Filter = filter ?? ((category, logLevel) => true); ScopeProvider = scopeProvider; _queueProcessor = loggerProcessor; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console = new WindowsLogConsole(); } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); } }