Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set outputTemplate for serilog 'WriteTo.Http'

Tags:

c#

serilog

2020-03-11 18:13:56.005 +05:30 DESKTOP-4EE5SF ZZZ [INF] Logging started.

Above log message is given when event is logged to file using serilog.

Log.Logger = new LoggerConfiguration()
                    .WriteTo.File("",
                        rollingInterval: RollingInterval.Day,
                        fileSizeLimitBytes: 1024 * 100,
                        outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {MachineName} ZZZ[{Level:u3}] {Message:lj}{NewLine}{Exception})                   
                    .CreateLogger();
Log.Information("Logging started.");    

how do I get same output using Serilog HTTP logger something like below

.WriteTo.Http(ConfigurationManager.AppSettings["httpLoggingPath"],
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {MachineName} ZZZ[{Level:u3}] {Message:lj}{NewLine}{Exception})
like image 202
InfoÁsith Avatar asked Nov 27 '25 11:11

InfoÁsith


1 Answers

You can't, the sink doesn't support output templates.

My take on output templates is that they are suited for sinks that produce an output to the user. The HTTP sink is more of a necessity for distributed computing when one wish to centralize the log events using a log server, e.g. Logstash.

I would really like to help you out. Can we move this discussion over to a new issue on the GitHub repository?

like image 72
FantasticFiasco Avatar answered Nov 29 '25 01:11

FantasticFiasco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!