# APM with Serilog spamming DiagnosticsListener to normal logs

**URL:** <https://discuss.elastic.co/t/apm-with-serilog-spamming-diagnosticslistener-to-normal-logs/358930>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [May 7, 2024, 1:53pm UTC](https://discuss.elastic.co/t/apm-with-serilog-spamming-diagnosticslistener-to-normal-logs/358930 "2024-05-07T13:53:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johannes\_Renatus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johannes_renatus/32/102228_2.png) [@Johannes\_Renatus](https://discuss.elastic.co/u/Johannes_Renatus)\
**Post date:** [May 7, 2024, 1:53pm UTC](https://discuss.elastic.co/t/apm-with-serilog-spamming-diagnosticslistener-to-normal-logs/358930/1 "2024-05-07T13:53:24Z")

</div>

**Kibana version** :  
7.17.9

**APM Server version** :  
`8.8.1`

**APM Agent language and version** :  
.net core C# =\> Elastic.Apm.NetCoreAll 1.26.0 and Serilog.Sinks.Elasticsearch 9.0.0

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

I've registered apm in program.cs  
app.UseAllElasticApm(app.Configuration);

I am also using Serilog and logging all my Application Logs to ES with Serilog.  
That works all fine. But since I am using APM it registered a lot of "HttpDiagnosticsSubscriber" on startup and my current debuglog on my console and on the ES Server in my Application Log looks like:

```auto
[15:30:43 INF] {RequestPipelineDiagnosticsListener} Received an CallElasticsearch.Start event from elasticsearch
[15:30:43 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Start event from elasticsearch
[15:30:43 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Stop event from elasticsearch
[15:30:43 INF] {HttpConnectionDiagnosticsListener} Received an ReceiveBody.Start event from elasticsearch
[15:30:43 INF] {HttpConnectionDiagnosticsListener} Received an ReceiveBody.Stop event from elasticsearch
[15:30:43 INF] {RequestPipelineDiagnosticsListener} Received an CallElasticsearch.Stop event from elasticsearch
[15:30:45 INF] {RequestPipelineDiagnosticsListener} Received an CallElasticsearch.Start event from elasticsearch
[15:30:45 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Start event from elasticsearch
[15:30:46 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Stop event from elasticsearch
[15:30:46 INF] {HttpConnectionDiagnosticsListener} Received an ReceiveBody.Start event from elasticsearch
[15:30:46 INF] {HttpConnectionDiagnosticsListener} Received an ReceiveBody.Stop event from elasticsearch
[15:30:46 INF] {RequestPipelineDiagnosticsListener} Received an CallElasticsearch.Stop event from elasticsearch
[15:30:48 INF] {RequestPipelineDiagnosticsListener} Received an CallElasticsearch.Start event from elasticsearch
[15:30:48 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Start event from elasticsearch
[15:30:48 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Stop event from elasticsearch
[15:30:48 INF] {HttpConnectionDiagnosticsListener} Received an ReceiveBody.Start event from elasticsearch
[15:30:48 INF] {HttpConnectionDiagnosticsListener} Received an ReceiveBody.Stop event from elasticsearch
[15:30:48 INF] {RequestPipelineDiagnosticsListener} Received an CallElasticsearch.Stop event from elasticsearch
[15:30:50 INF] {RequestPipelineDiagnosticsListener} Received an CallElasticsearch.Start event from elasticsearch
[15:30:50 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Start event from elasticsearch
[15:30:50 INF] {HttpConnectionDiagnosticsListener} Received an SendAndReceiveHeaders.Stop event from elasticsearch

```

It spams my hole Application log. Is there a way to disable this kind of logs for my Application ES Log Index?

I've tried to Override this in the appsettings.json but its not working:

```json
{
  "AppName": "automation-api",
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System.Net.Http.HttpClient": "Warning",
        "System": "Warning",
        "*HttpHandlerDiagnosticListener*": "Warning",
        "*RequestPipelineDiagnosticsListener*": "Warning"
      }
    }
  },
  "ElasticApm": {
    "ServerUrl": "https://elastic-apm.local.com",
    "ServiceName": "automation-api",
    "Environment": "development",
    "TransactionSampleRate": 1.0,
    "LogLevel": "Debug",
    "CaptureBody": "errors"
  },
  "AllowedHosts": "*"
}

```

---

<div class="post-metadata">

**Author:** ![Johannes\_Renatus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johannes_renatus/32/102228_2.png) [@Johannes\_Renatus](https://discuss.elastic.co/u/Johannes_Renatus)\
**Post date:** [May 8, 2024, 1:38pm UTC](https://discuss.elastic.co/t/apm-with-serilog-spamming-diagnosticslistener-to-normal-logs/358930/2 "2024-05-08T13:38:27Z")

</div>

The problem is that we use the nuget "Serilog.Sinks.Elasticsearch" which is not from ES itself and this makes this passive Problems.

We Megrated to Elastic.Serilog.Sinks and this solved our Problem

---

<div class="post-metadata">

**Author:** ![panyamred](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panyamred/32/134353_2.png) [@panyamred](https://discuss.elastic.co/u/panyamred)\
**Post date:** [May 9, 2024, 10:41am UTC](https://discuss.elastic.co/t/apm-with-serilog-spamming-diagnosticslistener-to-normal-logs/358930/3 "2024-05-09T10:41:39Z")

</div>

Hi,

How can we pass the extra configuration (including API Key for ES authentication) while using Elastic.Serilog.Sinks?

Thanks,

---

<div class="post-metadata">

**Author:** ![abbaskhalili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abbaskhalili/32/69004_2.png) [@abbaskhalili](https://discuss.elastic.co/u/abbaskhalili)\
**Post date:** [December 21, 2024, 6:29am UTC](https://discuss.elastic.co/t/apm-with-serilog-spamming-diagnosticslistener-to-normal-logs/358930/4 "2024-12-21T06:29:31Z")

</div>

```auto
loggerConfiguration.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticUrl))
{
    ModifyConnectionSettings = (c) =>
        c.ServerCertificateValidationCallback((sender, certificate, chain, errors) => true)
            .BasicAuthentication("serilog", "123y1easSbDWa2w"),
    FormatStackTraceAsArray = true,
    RegisterTemplateFailure = RegisterTemplateRecovery.IndexAnyway,
    IndexFormat = $"applog-{appName}-{environment}-{{0:yyyy.MM.dd}}",
    PipelineName = "application-applog",
    BufferRetainedInvalidPayloadsLimitBytes = 5000,
    BatchPostingLimit = 50,
    DetectElasticsearchVersion = true,
    EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog,
    TypeName = null
});

```
