简体   繁体   中英

Will the Serilog logging library work in a .net WPF application?

I have a .Net C# WPF application. I'm trying to add rolling logs to the app. In Asp.Net applications, we've previously used the package Serilog.

Does Serilog work .Net desktop (non-asp.net) applications? I googled around and saw there were some issues regarding it, but it wasn't clear to that they were actually resolved.

Here is what the initialization of my Serilog Logger looks like:

string logsDirectory = Path.Combine(Environment.CurrentDirectory, "logs");

// Configure Serilog pipeline
Log.Logger = new LoggerConfiguration()
   .MinimumLevel.Debug()
   .WriteTo.RollingFile(Path.Combine(logsDirectory, "log-{Date}.txt"))
   .CreateLogger();

I get the followint compilation error for "RollingLog()".

Error CS1061 'LoggerSinkConfiguration' does not contain a definition for 'RollingFile' and no extension method 'RollingFile' accepting a first argument of type 'LoggerSinkConfiguration' could be found (are you missing a using directive or an assembly reference?)

How can one git it to work with WPF?

You are missing the Serilog RollingFile NuGetPackage if you would like to use rolling logs:

Install-Package Serilog.Sinks.RollingFile

For more details on using this package, see here

As I commented on your question - Serilog is not ASP.Net specific, it is a generic C# logging library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM