Logging Service Name

Hello,
I have seen two other forum discussions regarding the Service Name, but none of those people were using the Logging Infrastructure Agent. My team is using the infrastructure agent for logging, so we are sending our logs via TCP.

Capture

Our logging solution looks like this:

Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .Enrich.FromLogContext()
                .Enrich.WithProperty("ServiceName", service)
                .WriteTo.File(new NewRelicFormatter(), filePath, LogEventLevel.Debug, rollingInterval: 
                    RollingInterval.Day)
                .WriteTo.TCPSink(
                    IPAddress.Parse(tcpAddress),
                    tcpPort,
                    new NewRelicFormatter(), LogEventLevel.Debug)
                .CreateLogger();

We tried to add the ServiceName as a property, but that doesn’t seem to help. It allows ut to search on a ServiceName attribute, but still no Service Name when diving into an individual log.

Any idea how to give a log record a “Service Name”?

Hi, @dominic.pilla: You may find this post helpful:

1 Like

Hi Phil,

So if I use service_name instead of ServiceName you think it will properly populate?

We have previously tried using service but that did not append the provided service name to the location I specified. We then tried ServiceName and that also did not work. I can give one of the few other options a try.

For instance, here is a log message with a Message.Properties.service attribute:
image

Thanks

Alright I just got it working. I am now using the below code as my LoggerConfiguration. I believe the Enrich.WithNewRelicLogsInContext populated the Service Name.

Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Debug()
            .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
            .Enrich.WithNewRelicLogsInContext()
            .Enrich.WithProperty("service_name", service)
            .WriteTo.File(new NewRelicFormatter(), filePath, LogEventLevel.Debug, rollingInterval: RollingInterval.Day)
            .WriteTo.TCPSink(
                IPAddress.Parse(tcpAddress),
                tcpPort,
                new NewRelicFormatter(), LogEventLevel.Debug)
            .CreateLogger();
2 Likes