-1

I'm using the package Serilog.Sinks.File I want to disable timestamp just for few messages without creating another instance of LoggerConfiguration for example-

Log.Logger = new LoggerConfiguration().WriteTo.File("logs/log.txt", outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}").CreateLogger();

Output:

2023-03-10 05:33:24 [INF] App started
2023-03-10 05:33:24 [INF] Some process1
2023-03-10 05:33:24 [INF] file1
2023-03-10 05:33:24 [INF] file2
2023-03-10 05:33:24 [INF] file3
2023-03-10 05:33:24 [INF] Operation completed.

I want:

2023-03-10 05:33:24 [INF] App started
2023-03-10 05:33:24 [INF] Some process1
file1
file2
file3
2023-03-10 05:33:24 [INF] Operation completed.

How to achieve this?

Dark Knight
  • 819
  • 8
  • 12

1 Answers1

0

Found the way. I created two logger objects with shared parameter true.

var logFilePath = "logs/log.txt";
var loggerConfiguration = new LoggerConfiguration().WriteTo.File(logFilePath, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}", shared: true).CreateLogger();
Log.Logger = loggerConfiguration;
var FilesLogger = new LoggerConfiguration().WriteTo.File(logFilePath, outputTemplate: "{Message}{NewLine}", shared: true).CreateLogger();
Dark Knight
  • 819
  • 8
  • 12