serilog-contrib / serilog-sinks-splunk

A Serilog sink that writes to Splunk
https://splunk.com
Apache License 2.0
46 stars 47 forks source link

AWS Serverless Lambda - synchronous logs #96

Closed bhavishyachandra closed 3 years ago

bhavishyachandra commented 6 years ago

Hello

I was using this sink to log to Splunk from my C# Serverless Lambda. We found that the platform kills all background threads after the API response is sent from the controller. This was causing some logs to go missing. Would be great if you could add an additional parameter that makes all the calls to Splunk synchronous in place of the periodic batching.

Thanks

merbla commented 6 years ago

@bhavishyachandra you most likely need to call Log.CloseAndFlush() before exiting.

https://merbla.com/2016/07/06/serilog-log-closeandflush/

JoryUK commented 4 years ago

I have a similar problem, although not with the splunk sink. And so may be completed unrelated if it is down to the sinks flush implementation.

I am calling Log.CloseAndFlush(); in a finally block in the Handle method. The faster the lambda execution the less chance i will get any logs written at all...

I have this lambda set to run every minute, it only logs during the cold start which took 1295.98 ms but every subsequent execution that takes 200 ms or less.. no logs.

I suspect CloseAndFlush is not synchronous...

oguzhancagliyan commented 4 years ago

Did you find a solution?

bhavishyachandra commented 4 years ago

@oguzhancagliyan I don't have a solution. we moved away from Lambda and hosted our API in a docker container.

lorenh commented 3 years ago

This is proving to be a big problem for us too. When sending logs directly to Splunk from a C# lambda (it's an aspnetcore app) they get dropped if the lambda executes quickly. Has anyone thought about ways to solve this in a clean way? Some sort of middleware that flushes on each request? Is there a way to just "flush" and not close?

merbla commented 3 years ago

Closing as a part of larger Serilog contrib reorg

Checkout https://github.com/serilog/serilog/issues/1627

skomis-mm commented 3 years ago

Hi @lorenh , wrote a snippets here