Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Serilog logging and an example of its usage for exceptions. #104

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/SmartCommander/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.ReactiveUI;
using Serilog;
using SmartCommander.Models;
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -35,6 +36,14 @@ public static void Main(string[] args)
}
}
else {
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
#if DEBUG
.WriteTo.Console()
#endif
.WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();

BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}

Expand Down
5 changes: 4 additions & 1 deletion src/SmartCommander/SmartCommander.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.10.9" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.5.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Assets\Resources.Designer.cs">
Expand Down
16 changes: 8 additions & 8 deletions src/SmartCommander/ViewModels/FileSearchViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia.Threading;
using ReactiveUI;
using Serilog;
using SmartCommander.Extensions;
using SmartCommander.ViewModels;
using System;
Expand Down Expand Up @@ -74,19 +75,18 @@ public async Task<bool> SearchAsync(string folderPath, string searchPattern, Can
cancellationToken.ThrowIfCancellationRequested();
await SearchAsync(subDir, searchPattern, cancellationToken);
}
}
// TODO: add logging
/*
catch (OperationCanceledException)
}
catch (OperationCanceledException e)
{
Log.Error("OperationCanceledException: " + e.Message);
}
catch (UnauthorizedAccessException e)
{
}
*/
catch (Exception)
Log.Error("UnauthorizedAccessException: " + e.Message);
}
catch (Exception e)
{

Log.Error("Exception: " + e.Message);
}

return true;
Expand Down
Loading