Closed a11smiles closed 3 months ago
Hey, I have no opportunity to reproduce in Azure Fn right now.
But on the first view it looks like you rely on a static logger, which is flushed in the end. But I expect that your host will be running and that line will be executed before the shutdown.
I would suggest adding a logger into DI in the same way as it is done in the sample web app and check will the behavior be different
Here's the source for a sample endpoint:
using System.Collections.Generic;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
namespace Fns.Logging;
public class Log
{
private readonly ILogger _logger;
public Log(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Log>();
}
[Function("Log")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
FunctionContext executionContext)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Welcome to Azure Functions!");
return response;
}
}
As you can see, I'm injecting the logger into the endpoint and attempting to log information to the sink.
Just FYI, my firewall does not show any calls being made out to grafana from my machine, not even on application shutdown (which should at least flush the stream).
Figured this out. Some of the documentation (not yours) was out of date. Sorry for the hassle.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue.
Which version of Serilog.Sinks.Grafana.Loki are you using?
8.3.0
Which version of .NET are you using?
net8.0
Describe the bug
I'm developing an Azure function. While it's logging to the console, it's not sending any information to the hosted Loki service.
Here's my code:
To Reproduce
See above code. Running Azure Function in isolated mode.
Expected behavior
Send logs to public (hosted) Loki service.
Log/SelfLog output or exception with stacktrace
No response
Application or code sample, which could be used to reproduce a bug
No response
Additional context
No response
I have read the documentation