Skip to content

Commit

Permalink
Improve sanitation error log (#487)
Browse files Browse the repository at this point in the history
* Improve sanitation error log

* Include message always
  • Loading branch information
einarmo authored Oct 30, 2024
1 parent fb075de commit b142f90
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Cognite.Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ public static void LogCogniteError<TError>(this ILogger logger,
{
throw new ArgumentNullException(nameof(error));
}
string? cogniteString = null;
string cogniteString = error.Message ?? "";
if (error.Exception != null && error.Exception is ResponseException rex)
{
cogniteString = $" RequestId: {rex.RequestId}, CDF Message: {rex.Message}";
cogniteString += $" RequestId: {rex.RequestId}, CDF Message: {rex.Message}";
}
else if (error.Exception != null)
{
cogniteString = $" Non-CDF Error of type: {error.Exception.GetType()}";
cogniteString += $" Non-CDF Error of type: {error.Exception.GetType()}";
if (!string.IsNullOrWhiteSpace(error.Exception.Message))
{
cogniteString += $", Message: {error.Exception.Message}";
}
}

string? valueString = null;
string valueString = "";
if (error.Values != null && error.Values.Any())
{
valueString = string.Join(", ", error.Values.Select(idt => idt.ExternalId ?? idt.Id.ToString()));
valueString = " Values: " + string.Join(", ", error.Values.Select(idt => idt.ExternalId ?? idt.Id.ToString())) + ".";
}
string resourceName;
switch (requestType)
Expand Down Expand Up @@ -105,9 +105,9 @@ public static void LogCogniteError<TError>(this ILogger logger,
error.Resource, error.Skipped?.Count() ?? 0, resourceName, cogniteString);
break;
case ErrorType.SanitationFailed:
logger.Log(handledLevel, "Sanitation of {resource} with values: {values} failed, " +
"resulting in the full or partial removal of {cnt} {name} from the request.{cdf}",
error.Resource, valueString, error.Skipped?.Count() ?? 0, resourceName, cogniteString);
logger.Log(handledLevel, "Sanitation of {resource} failed due to invalid {field}, " +
"resulting in the full or partial removal of {cnt} {name} from the request.{valueString}{cdf}",
resourceName, error.Resource, error.Skipped?.Count() ?? 0, resourceName, valueString, cogniteString);
break;
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public static void LogResult<TResult, TError>(this ILogger logger,
logger.Log(infoLevel, "Request of type {type} had {cnt} results with {cnt2} errors",
requestType, successCount, errorCount);
}


if (result.Errors != null)
{
Expand Down

0 comments on commit b142f90

Please sign in to comment.