public static void LogProcessor___Valid___Works() { var tempFileName = Path.GetTempFileName(); try { // Arrange var configuration = new FileLogConfig(LogInclusionKindToOriginsMaps.ExceptionsFromAnywhere, tempFileName); var processor = new FileLogWriter(configuration); var infoCanary = A.Dummy <string>(); var errorCanary = new ArgumentException(A.Dummy <string>()); // Act processor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); processor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); // Assert var fileContents = File.ReadAllText(tempFileName); fileContents.Should().NotContain(infoCanary); fileContents.Should().Contain(errorCanary.Message); } finally { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } } }
public static void LogProcessor___Valid___Works() { var tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); try { // Arrange var configuration = new TimeSlicedFilesLogConfig(LogInclusionKindToOriginsMaps.AnythingFromAnywhere, tempDirectory, "TestFile", TimeSpan.FromMinutes(1)); var processor = new TimeSlicedFilesLogWriter(configuration); var infoCanary = A.Dummy <string>(); var errorCanary = new ArgumentException(A.Dummy <string>()); // Act processor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); processor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); // Assert var files = Directory.GetFiles(tempDirectory); files.Should().NotBeEmpty(); } finally { if (Directory.Exists(tempDirectory)) { Directory.Delete(tempDirectory, true); } } }
public static void LogProcessor___Valid___Works() { using (var consoleOut = new StringWriter(CultureInfo.CurrentCulture)) { using (var consoleError = new StringWriter(CultureInfo.CurrentCulture)) { // Arrange var infoCanary = A.Dummy <string>(); var errorCanary = new ArgumentException(A.Dummy <string>()); var logProcessor = new ConsoleLogWriter(new ConsoleLogConfig(LogInclusionKindToOriginsMaps.AnythingFromAnywhere, LogInclusionKindToOriginsMaps.StringAndObjectsFromItsLogEntryPosted, LogInclusionKindToOriginsMaps.ExceptionsFromAnywhere)); Console.SetOut(consoleOut); Console.SetError(consoleError); // Act logProcessor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); logProcessor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); var consoleOutOutput = consoleOut.ToString(); var consoleErrorOutput = consoleError.ToString(); // Assert consoleOutOutput.Should().Contain(infoCanary); consoleOutOutput.Should().NotContain(errorCanary.Message); consoleErrorOutput.Should().Contain(errorCanary.Message); consoleErrorOutput.Should().NotContain(infoCanary); } } }
public static void LogProcessor___Valid___Works() { // Arrange var configuration = new InMemoryLogConfig(LogInclusionKindToOriginsMaps.AnythingFromAnywhere); var processor = new InMemoryLogWriter(configuration); var infoCanary = A.Dummy <string>(); var errorCanary = new ArgumentException(A.Dummy <string>()); // Act processor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); processor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted)); // Assert processor.LoggedItems.Count.Should().Be(2); processor.LoggedItems.Single(_ => _.Context.Origin == LogItemOrigin.ItsLogEntryPosted.ToString() && _.Kind == LogItemKind.String).Subject.Summary.Should().Contain(infoCanary); processor.LoggedItems.Single(_ => _.Context.Origin == LogItemOrigin.ItsLogEntryPosted.ToString() && _.Kind == LogItemKind.Exception).Subject.Summary.Should().Contain(errorCanary.Message); }