Þórir Sachie
Þórir Sachie

Reputation: 229

HostingEnviornment.QueueBackgroundWorkItem equivalent for Azure Functions

I'm writing a custom logger that write logs from Azure Functions to a target over the network. This logger needs to be fire-and-forget asynchronous – it would be too slow to await each log write. However, I wouldn't want the last few log entries to be lost each time the host is shut down. Is there a way of registering my asynchronous operations for writing the logs using something equivalent to HostingEnviornment.QueueBackgroundWorkItem?

Upvotes: 2

Views: 216

Answers (1)

Stephen Cleary
Stephen Cleary

Reputation: 457167

AFAIK, there's currently nothing like QueueBackgroundWorkItem for Azure Functions (modern equivalents being IApplicationLifetime / IHost); Azure Functions does use these under the covers, but that level of configuration isn't available for end-user code. In the general case, there's Durable Functions, but that would be overkill to use just for logging.

Perhaps your logging system could use some work. I have an AF that streams its logs out to a compressed Azure blob. I flush it before returning the AF result, and I've been pleased with the performance so far.

Upvotes: 1

Related Questions