Search code examples
c#wpfserilog.net-core-3.0

Publishing WPF .Net Core 3 app and Serilog.Sinks.File


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.


Solution

  • 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.