Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is difference between Serilog.Sinks.File and Serilog.Extensions.Logging.File?

what is difference between Serilog.Sinks.File and Serilog.Extensions.Logging.File packages in asp.net core?

When I tried to implement logging in asp.net core project with Serilog I found a quick example here which used Serilog.Sinks.File.

When I tried to implement the same in my project,the logger factory didnt have the extension AddFile().

But when I added another extension Serilog.Extensions.Logging.File I got the extension.

Are both extensions needed? or just Logging.File extension is enough?

What is the basic difference Sinks.File and Logging.File ?

like image 340
Mahesh Gupta Avatar asked Sep 13 '25 01:09

Mahesh Gupta


1 Answers

In the link you provided, the example explicitly use Serilog.Extensions.Logging.File.

It is this extension that provide the AddFile method to ILoggerFactory (via Extension Methods mecanisms in DotNet) :

Extension of Microsoft.Extensions.Logging.IloggerFactory

A quick look at the Nuget package definition of Serilog.Extensions.Logging.File indicates that it has a dependency on Serilog.Sinks.RollingFile. The latter extension itself has a dependency on Serilog.Sinks.File.

So, Serilog.Extensions.Logging.File extends ILoggerFactory, providing the AddFile() method. That method uses the RollingFile class (as seen in the source code).

like image 56
Lex Lustor Avatar answered Sep 15 '25 18:09

Lex Lustor