0

I am using InfluxDB.client in my .NET 8.0 worker application. When running the code using dotnet run, I do not get the logs below. When I compile it to a selfcontained application and run it using systemd on the controller it fills up the journalctl on the controller with these messages every time a datapoint is sent to the server:

Sep 04 02:52:12 compulab-imx8mp TSLogger[1138]: Flushing batches before shutdown.
Sep 04 02:52:12 compulab-imx8mp TSLogger[1138]: The data was successfully written to InfluxDB 2.
Sep 04 02:52:12 compulab-imx8mp TSLogger[1138]: The batch item: OnNext(RestSharp.RestResponse) was processed successfully.
Sep 04 02:52:12 compulab-imx8mp TSLogger[1138]: The WriteApi was disposed.
Sep 04 02:52:12 compulab-imx8mp TSLogger[1138]: The data was successfully written to InfluxDB 2.
Sep 04 02:52:12 compulab-imx8mp TSLogger[1138]: The batch item: OnNext(RestSharp.RestResponse) was processed successfully.
Sep 04 02:52:12 compulab-imx8mp TSLogger[1138]: The WriteApi was disposed.

Relevant InfluxDB Code:

string tokenInfluxDb = cabinetConfig.InfluxDb.Token;
string urlInfluxDb = cabinetConfig.InfluxDb.Url;
string org = cabinetConfig.InfluxDb.Org;
string bucket = cabinetConfig.InfluxDb.Bucket;

clientInfluxDb = new InfluxDBClient(urlInfluxDb, tokenInfluxDb);

var point = PointData
    .Measurement(item.Cage)
    .Field(item.MeasurementId, value)
    .Tag("sn", item.SerialNumber)
    .Timestamp(DateTime.UtcNow, WritePrecision.Ns);

LogToDb(point);

async void LogToDb(PointData point)
{
    using (var writeApi = clientInfluxDb.GetWriteApi())
    {
        writeApi.WritePoint(point, bucket, org);
    }
}

Worker.csproj:

<TargetFramework>net8.0</TargetFramework>
<PackageReference Include="InfluxDB.Client" Version="4.14.0" />

systemd service file:

[Unit]
Description=InfluxDBWorker

[Service]
ExecStartPre=/bin/sleep 30
WorkingDirectory=/home/usr/application/InfluxDBWorker
ExecStart=/home/usr/application/InfluxDBWorker/InfluxDBWorker
Restart=always
# Restart service after 60 seconds if the dotnet service crashes:
RestartSec=60
KillSignal=SIGINT
SyslogIdentifier=InfluxDBWorker
User=root
Environment=DOTNET_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

I have tried setting different logging parameters to warning in Environment variables and in appsettings.json, but it seems like these are coming from elsewhere.

I tried setting ForwardToConsole=no in journald.conf.

I have not been able to disable this. I found this: https://github.com/influxdata/influxdb-client-csharp/issues/560 , but I could make it work.

1 Answer 1

0

My problem:

I developed a .NET 8 rest API to register data on InfluxDB, so I deployed it on Ubuntu 24.X, After seeing the journalctl was spamming the syslog file, I tried to stop influx from writing logs, but the issue is Influxd or Influxdb weren't writing to syslog, it was the influx client for C#

My Solution Try adding this class:

using System.Diagnostics;
using InfluxDB.Client.Core;

namespace Services;

public static class InfluxDBTraceFilter
{
    public static void SuppressInfluxVerbose()
    {
        // Clear existing listeners to avoid conflicts
        Trace.Listeners.Clear();

        // Add a listener that filters out logs below Warning level
        Trace.Listeners.Add(new DefaultTraceListener
        {
            Filter = new EventTypeFilter(SourceLevels.Warning)
        });

        // Disable InfluxDB verbose logging explicitly
        Trace.AutoFlush = false;
        Trace.WriteLine("InfluxDB verbose logging suppressed.");
    }
}

Now on your Program.cs or Starup.cs add this line:

InfluxDBTraceFilter.SuppressInfluxVerbose();
#In my case it was on line 19 

var bld = WebApplication.CreateBuilder(args);

DotEnv.Load();

InfluxDBTraceFilter.SuppressInfluxVerbose();

also if you have appsettings.json files set this configuration

"Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft.AspNetCore": "Warning",
      "InfluxDB.Client": "Warning"
    }

Then make your tests on your local verify everything and now you can deploy your app, my advice is to clear your syslog first to see a difference.

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.