Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serilog overwrite file

Tags:

.net

serilog

How does one configure Serilog so it overwrites the file every time the program executes?


Code

   Log.Logger = new LoggerConfiguration()
      .MinimumLevel.Debug()
      .WriteTo.ColoredConsole()
      .WriteTo.File("c:\\Logs\\myapp.log")
      .CreateLogger();

It doesn't hurt to append the entry logs of the new execution but during development is convenient just getting the current ones.

like image 459
ldonoso Avatar asked Feb 23 '17 10:02

ldonoso


Video Answer


1 Answers

As suggested in the comment above, deleting the file with System.IO.File.Delete() is the way to go:

File.Delete("c:\\Logs\\myapp.log");
like image 181
Nicholas Blumhardt Avatar answered Oct 25 '22 06:10

Nicholas Blumhardt