public async Task Should_ignore_exception_from_source() { var result2 = new SearchResults().Add("Name2", SearchResultType.Setting, "Url2"); var query = "a query"; A.CallTo(() => source1.SearchAsync(query, requestContext)) .Throws(new InvalidOperationException()); A.CallTo(() => source2.SearchAsync(query, requestContext)) .Returns(result2); var result = await sut.SearchAsync(query, requestContext); result.Should().BeEquivalentTo(result2); A.CallTo(() => log.Log(A <SemanticLogLevel> ._, A <string> ._, A <Exception?> ._, A <LogFormatter <string> > ._ !)) .MustHaveHappened(); }
private static void LogMessage(ISemanticLog log, LogMessage message) { var level = SemanticLogLevel.Information; switch (message.Level) { case SyslogLevel.Emergency: level = SemanticLogLevel.Error; break; case SyslogLevel.Alert: level = SemanticLogLevel.Error; break; case SyslogLevel.Critical: level = SemanticLogLevel.Error; break; case SyslogLevel.Error: level = SemanticLogLevel.Error; break; case SyslogLevel.Warning: level = SemanticLogLevel.Warning; break; case SyslogLevel.Notice: level = SemanticLogLevel.Information; break; case SyslogLevel.Info: level = SemanticLogLevel.Information; break; case SyslogLevel.Debug: level = SemanticLogLevel.Debug; break; } log.Log <None>(level, default, (_, w) => w
public static void LogError(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Error, None.Value, (_, w) => objectWriter(w)); }
public static void LogWarning(this ISemanticLog log, Exception exception, LogFormatter action) { log.Log(SemanticLogLevel.Warning, exception, action); }
public static void LogFatal(this ISemanticLog log, Exception exception, Action <IObjectWriter> objectWriter = null) { log.Log(SemanticLogLevel.Fatal, writer => writer.WriteException(exception, objectWriter)); }
private void MustLogWarning() { A.CallTo(() => log.Log(SemanticLogLevel.Warning, A <None> .Ignored, A <Action <None, IObjectWriter> > .Ignored)) .MustHaveHappened(); }
public void Should_generate_400_for_ValidationException() { var errors = new List <ValidationError> { new ValidationError("Error1"), new ValidationError("Error2", "Property0"), new ValidationError("Error3", "Property1", "Property2"), new ValidationError("Error4", "Property3.Property4"), new ValidationError("Error5", "Property5[0].Property6") }; var ex = new ValidationException(errors); var context = Error(ex); sut.OnException(context); var result = (ObjectResult)context.Result !; Assert.Equal(400, result.StatusCode); Assert.Equal(400, (result.Value as ErrorDto)?.StatusCode); Assert.Equal(new[] { "Error1", "property0: Error2", "property1, property2: Error3", "property3.property4: Error4", "property5[0].property6: Error5" }, ((ErrorDto)result.Value).Details); A.CallTo(() => log.Log(A <SemanticLogLevel> ._, A <Exception?> ._, A <LogFormatter> ._ !)) .MustNotHaveHappened(); }
public static void LogFatal(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log <None>(SemanticLogLevel.Fatal, null, (_, w) => objectWriter(w)); }
public static void LogFatal(this ISemanticLog log, Exception exception, Action <IObjectWriter> objectWriter = null) { log.Log <None>(SemanticLogLevel.Fatal, null, (_, w) => w.WriteException(exception, objectWriter)); }
public static void LogFatal(this ISemanticLog log, Exception?exception, Action <IObjectWriter>?objectWriter = null) { log.Log(SemanticLogLevel.Fatal, None.Value, (_, w) => w.WriteException(exception, objectWriter)); }
public static void LogInformation(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log <None>(SemanticLogLevel.Information, null, (_, w) => objectWriter(w)); }
public static void LogFatal <T>(this ISemanticLog log, Exception?exception, T context, LogFormatter <T> action) { log.Log(SemanticLogLevel.Fatal, context, exception, action); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { SemanticLogLevel semanticLogLevel; switch (logLevel) { case LogLevel.Trace: semanticLogLevel = SemanticLogLevel.Trace; break; case LogLevel.Debug: semanticLogLevel = SemanticLogLevel.Debug; break; case LogLevel.Information: semanticLogLevel = SemanticLogLevel.Information; break; case LogLevel.Warning: semanticLogLevel = SemanticLogLevel.Warning; break; case LogLevel.Error: semanticLogLevel = SemanticLogLevel.Error; break; case LogLevel.Critical: semanticLogLevel = SemanticLogLevel.Fatal; break; default: semanticLogLevel = SemanticLogLevel.Debug; break; } semanticLog.Log(semanticLogLevel, writer => { var message = formatter(state, exception); if (!string.IsNullOrWhiteSpace(message)) { writer.WriteProperty(nameof(message), message); } if (eventId.Id > 0) { writer.WriteObject(nameof(eventId), eventIdWriter => { eventIdWriter.WriteProperty("id", eventId.Id); if (!string.IsNullOrWhiteSpace(eventId.Name)) { eventIdWriter.WriteProperty("name", eventId.Name); } }); } if (state is IReadOnlyList <KeyValuePair <string, object> > parameters) { foreach (var kvp in parameters) { if (kvp.Value != null) { var key = kvp.Key.Trim('{', '}', ' '); if (key.Length > 2 && !string.Equals(key, "originalFormat", StringComparison.OrdinalIgnoreCase)) { writer.WriteProperty(key.ToCamelCase(), kvp.Value.ToString()); } } } } if (exception != null) { writer.WriteException(exception); } }); }
public static void LogFatal(this ISemanticLog log, Exception?exception, LogFormatter action) { log.Log(SemanticLogLevel.Fatal, exception, action); }
public static void LogFatal(this ISemanticLog log, LogFormatter action) { log.Log(SemanticLogLevel.Fatal, null, action); }
public static void LogError <T>(this ISemanticLog log, Exception exception, T context, LogFormatter <T> action) { log.Log(SemanticLogLevel.Error, context, exception, action); }
public static void LogError(this ISemanticLog log, Exception exception, LogFormatter action) { log.Log(SemanticLogLevel.Error, exception, action); }
public static void LogError(this ISemanticLog log, LogFormatter action) { log.Log(SemanticLogLevel.Error, null, action); }
public static void LogTrace(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Trace, objectWriter); }
public static void LogDebug(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Debug, objectWriter); }
public static void LogWarning <T>(this ISemanticLog log, T context, Action <T, IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Warning, context, objectWriter); }
public static void LogInformation(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Information, objectWriter); }
public static void LogFatal <T>(this ISemanticLog log, T context, Action <T, IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Fatal, context, objectWriter); }
public static void LogWarning(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Warning, objectWriter); }
public static void LogFatal <T>(this ISemanticLog log, Exception exception, T context, Action <T, IObjectWriter> objectWriter = null) { log.Log(SemanticLogLevel.Fatal, context, (ctx, w) => w.WriteException(exception, ctx, objectWriter)); }
public static void LogError(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Error, objectWriter); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { SemanticLogLevel semanticLogLevel; switch (logLevel) { case LogLevel.Trace: semanticLogLevel = SemanticLogLevel.Trace; break; case LogLevel.Debug: semanticLogLevel = SemanticLogLevel.Debug; break; case LogLevel.Information: semanticLogLevel = SemanticLogLevel.Information; break; case LogLevel.Warning: semanticLogLevel = SemanticLogLevel.Warning; break; case LogLevel.Error: semanticLogLevel = SemanticLogLevel.Error; break; case LogLevel.Critical: semanticLogLevel = SemanticLogLevel.Fatal; break; default: semanticLogLevel = SemanticLogLevel.Debug; break; } if (state is IReadOnlyList <KeyValuePair <string, object> > parameters) { foreach (var(_, value) in parameters) { if (value is Exception ex && exception == null) { exception = ex; } } } var context = (eventId, state, exception, formatter); semanticLog.Log(semanticLogLevel, context, exception, (ctx, writer) => { var message = ctx.formatter(ctx.state, ctx.exception); if (!string.IsNullOrWhiteSpace(message)) { writer.WriteProperty(nameof(message), message); } if (ctx.eventId.Id > 0) { writer.WriteObject("eventId", ctx.eventId, (innerEventId, eventIdWriter) => { eventIdWriter.WriteProperty("id", innerEventId.Id); if (!string.IsNullOrWhiteSpace(innerEventId.Name)) { eventIdWriter.WriteProperty("name", innerEventId.Name); } }); } if (ctx.state is IReadOnlyList <KeyValuePair <string, object> > parameters2) { foreach (var(key, value) in parameters2) { if (value != null) { var trimmedName = key.Trim('{', '}', ' '); if (trimmedName.Length > 2 && !string.Equals(trimmedName, "exception", StringComparison.OrdinalIgnoreCase) && !string.Equals(trimmedName, "originalFormat", StringComparison.OrdinalIgnoreCase)) { writer.WriteProperty(trimmedName.ToCamelCase(), value.ToString()); } } } }
public static void LogFatal(this ISemanticLog log, Action <IObjectWriter> objectWriter) { log.Log(SemanticLogLevel.Fatal, objectWriter); }
private void MustLogWarning() { A.CallTo(() => log.Log(A <SemanticLogLevel> ._, A <Exception?> ._, A <LogFormatter> ._ !)) .MustHaveHappened(); }
public static void LogWarning <T>(this ISemanticLog log, T context, LogFormatter <T> action) { log.Log(SemanticLogLevel.Warning, context, null, action); }