0
votes

I'm using Serilog in an Azure Worker Role & a WebApi with the ElasticSearch sink.

Everything works fine on the Worker Role.

On the WebApi I tried the Trace & Email sinks and they work fine. ElasticSearch sink is not logging at all.

Here is my configuration:

var logger = new LoggerConfiguration()
                   .MinimumLevel.Information()
                   .WriteTo.Trace()
                   .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("https://myElasticServer")))
                   .CreateLogger();

If I try to write Logs in a controller, I have them in the Trace but nothing in Trace.

1

1 Answers

1
votes

The problem came from a self signed certificate.

I've created my own CertificateValidation method to ignore certificate validation based on an exclusion list

private bool MyCertificateValidationCallback(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    if (sslPolicyErrors == SslPolicyErrors.None)
        return true;

    var request = sender as HttpWebRequest;

    if (request != null)
    {
        var exclusion = ConfigurationManager.AppSettings["CertificateExclusion"];

        if (exclusion.Contains(request.Host))
            return true;
    }

    return false;
}

And register it when the application starts

ServicePointManager.ServerCertificateValidationCallback = MyCertificateValidationCallback;