NLog using .NET Core windows service


I am trying to log a windows service as a proof of concept. I have the infrastructure and .NET agents installed on my machine and at least the infra agent is connected and sending data to my account. The service currently uses NLog and I have the target set up, I am populating the JSON file with the New Relic log format entries as expected. Config files all have my license key in them, but logs do not appear in the New Relic Log UI.

Is there additional configuration required to push these log entries to New Relic? The only example on the docs page is fluentd which we are not using - do I need to install fluentd in order to push the logs up?


This was an issue with my infrastructure agent. For clarity, here is my (currently working) setup:

  • .NET Core 3.1 console app, uses BackgroundService and is installed as a service on local machines (not servers)
  • In the application, logging configured:
var newRelicFileTarget = new FileTarget("NewRelic");
newRelicFileTarget.Layout = new NewRelicJsonLayout();
newRelicFileTarget.FileName = "C:\path\to\NLog.json";

var loggerConfig = new LoggingConfiguration();

LogManager.Configuration = loggerConfig;

// _logger is a private NLog.ILogger member
_logger = LogManager.GetLogger("ServiceName");

This basically follows the documentation and prints the log messages to NLog.json in the required format for New Relic. It uses NewRelic.Api.Agent and NewRelic.LogEnrichers.NLog.

The piece I had incorrect was the infrastructure agent setup. I created a file but the content wasn’t exactly how it needed to be. Here is a minimum working example for C:\Program Files\New Relic\newrelic-infra\logging.d\:

  - name: servicename-nlog
    file: C:\path\to\NLog.json # NLog file from logging above

I did not have to restart the infra agent in order for logs to get sent.