public void WritesFormattedMessageToTextWriter(LogSeverity severity, string message, bool includeException, string expectedText) { StringWriter writer = new StringWriter(); writer.NewLine = "\n"; var logger = new SeverityPrefixLogger(new TextLogger(writer)); logger.Log(severity, message, includeException ? new Exception("Foo") : null); Assert.AreEqual(expectedText, writer.ToString()); }
public void LoggerAndParserAreSymmetrical(LogSeverity severity) { const string message = "Message"; StringWriter writer = new StringWriter(); writer.NewLine = "\n"; var logger = new SeverityPrefixLogger(new TextLogger(writer)); logger.Log(severity, message); var parser = new SeverityPrefixParser(); LogSeverity parsedSeverity; string parsedMessage; bool hasSeverity = parser.ParseLine(writer.ToString().Trim(), out parsedSeverity, out parsedMessage); Assert.AreEqual(severity, parsedSeverity); Assert.AreEqual(message, parsedMessage); Assert.IsTrue(hasSeverity); }
public void ToleratesAppDomainUnload() { StringWriter logWriter = new StringWriter(); var logger = new SeverityPrefixLogger(new TextLogger(logWriter)); var hostFactory = (IsolatedAppDomainHostFactory)RuntimeAccessor.ServiceLocator.ResolveByComponentId(IsolatedAppDomainHostFactory.ComponentId); using (IHost host = hostFactory.CreateHost(new HostSetup(), logger)) { HostAssemblyResolverHook.InstallCallback(host); host.GetHostService().Do<object, object>(RemoteCallback, null); } Assert.AreEqual("", logWriter.ToString(), "A dangling Db4o client may have caused the AppDomain.Unload to fail. Check the DomainUnload event handling policy for the client."); }