diff --git a/CoDepend/Application/DependencyGraphBuilder.cs b/CoDepend/Application/DependencyGraphBuilder.cs index 44446e6..197b571 100644 --- a/CoDepend/Application/DependencyGraphBuilder.cs +++ b/CoDepend/Application/DependencyGraphBuilder.cs @@ -8,7 +8,7 @@ using CoDepend.Domain.Models; using CoDepend.Domain.Models.Records; using CoDepend.Domain.Utils; - +using CoDepend.Infra.Logger; namespace CoDepend.Application; public sealed class DependencyGraphBuilder(IReadOnlyList _dependencyParsers, BaseOptions _options) @@ -100,7 +100,10 @@ private async Task TryClassifyItem( } } catch (OperationCanceledException) { throw; } - catch (Exception ex) { await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); } + catch (Exception ex) { + //await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); + Logger.LogError("Error while processing '{item.Value}': {ex}"); + } } private async Task Deps)>> ParseAllAsync( @@ -132,7 +135,8 @@ await Parallel.ForEachAsync( catch (OperationCanceledException) { throw; } catch (Exception ex) { - await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); + //Task task = Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); + Logger.LogError("Error while processing " + item.Value + ":" + ex?.ToString()); return null; } } diff --git a/CoDepend/Domain/DependencyGraphSerializer.cs b/CoDepend/Domain/DependencyGraphSerializer.cs index 709109a..d6ae94e 100644 --- a/CoDepend/Domain/DependencyGraphSerializer.cs +++ b/CoDepend/Domain/DependencyGraphSerializer.cs @@ -5,6 +5,7 @@ using CoDepend.Domain.Models.Records; using MessagePack; using MessagePack.Resolvers; +using CoDepend.Infra.Logger; namespace CoDepend.Domain; @@ -109,7 +110,15 @@ public static byte[] Serialize(ProjectDependencyGraph graph, int version = 1) DependsOn = dependsOn, }; - return MessagePackSerializer.Serialize(dto, MsgPackOptions); + var result = MessagePackSerializer.Serialize(dto, MsgPackOptions); + if(result?.Length > 0) { + Logger.LogInformation(result.Length.ToString()); + } else + { + Logger.LogWarning("Empty array returned"); + } + + return result ?? Array.Empty();; } public static ProjectDependencyGraph Deserialize(byte[] data, string projectRoot) diff --git a/CoDepend/Infra/Logger/Logger.cs b/CoDepend/Infra/Logger/Logger.cs new file mode 100644 index 0000000..16d801d --- /dev/null +++ b/CoDepend/Infra/Logger/Logger.cs @@ -0,0 +1,22 @@ +using System; +namespace CoDepend.Infra.Logger; + +#pragma warning disable CA1050 // Declare types in namespaces +public class Logger +#pragma warning restore CA1050 // Declare types in namespaces +{ + public static void LogInformation(string message) + { + Console.WriteLine($"INFO: {message}"); + } + + public static void LogWarning(string message) + { + Console.WriteLine($"WARN: {message}"); + } + + public static void LogError(string message) + { + Console.WriteLine($"ERROR: {message}"); + } +} \ No newline at end of file