3
votes

NuGet package Serilog.Sinks.File gives an error when publishing.

I am trying to publish a self-contained WPF .NET Core 3.0 app. The app builds, runs fine publishes fine until Serilog.Sinks.File is added. Once Serilog.Sinks.File is added to the project, the app builds/runs and even logs correctly. However, when trying to publish this error is given;

System.AggregateException: One or more errors occurred. ---> System.Exception: Publishing failed. --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at Microsoft.Publish.Framework.Model.DefaultPublishSteps.<>c__DisplayClass26_0.b__2() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Publish.Framework.Model.DefaultPublishSteps.d__23.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Publish.Framework.ViewModel.ProfileSelectorViewModel.d__205.MoveNext() ---> (Inner Exception #0) System.Exception: Publishing failed.<---

System.Exception: Publishing failed.

===================

Remove Serilog.Sinks.File and the app publishes.

Even removing the Serilog initialize command and the same error occurs.

1
Did you check the exception(s) inside the AggregateException to see if it gives any clue?C. Augusto Proiete
@CaioProiete not really, the output in VS, just says Build: 11 succeeded, 0 failed, 0 up-to-date, 0 skipped, then Publish: 0 succeeded, 1 failed, 0 skipped. No actual error in the output. A message box appears pointing to a temp file with the above error message.Xaphann
Oh that's a shame the log is not flattening the exceptions within the Agg Exception.C. Augusto Proiete
Long shot: Are you configuring the File log via appSettings.json or app.config? If you are, it's possible the build process is failing to detect the dependency to the File sink... It's worth a quick test... Just put this Console.WriteLine(typeof(Serilog.FileLoggerConfigurationExtensions)); somewhere in the startup of your app, to create a static dependency to the File Sink assembly, and see if that helps.C. Augusto Proiete
@CaioProiete found the solution, see belowXaphann

1 Answers

2
votes

I found the solution turns out that Serilog.Sinks.File is not the correct Nuget package. You need to use Serilog.AspNetCore and then the app is able to publish.