APM Instrumentation of Windows .NET framework console application

Agents question template

We are currently monitoring a set of IIS application successfully. We have tried to extend the monitoring to some C# .NET console applications running as scheduled tasks on the same host however, despite configuring the applications as per the guides, we are not seeing any telemetry at all being logged in the APM. The applications appear to be communicating with NewRelic as they are shown in APM with the correct names as configured in the application configs however there is literally no data being reported.

Checking the local NewRelic logs, for both the application itself and the individual PID created for the agent, shows that the modules are being instrumented. We have also tried re-configuring the NewRelic.config with additional parameters believing this to be case of the applications starting up, processing and closing before the data is sent to NewRelic - however none of these settings have worked either.

and

https://one.eu.newrelic.com/launcher/nr1-core.explorer?launcher=eyJzZWxlY3RlZEluc3RhbmNlIjpudWxsfQ==&pane=eyJuZXJkbGV0SWQiOiJhcG0tbmVyZGxldHMub3ZlcnZpZXciLCJlbnRpdHlJZCI6Ik1qYzVOek14T1h4QlVFMThRVkJRVEVsRFFWUkpUMDU4TVRBd01EZzBPRFV5In0=&sidebars[0]=eyJuZXJkbGV0SWQiOiJucjEtY29yZS5hY3Rpb25zIiwiZW50aXR5SWQiOiJNamM1TnpNeE9YeEJVRTE4UVZCUVRFbERRVlJKVDA1OE1UQXdNRGcwT0RVeSIsInNlbGVjdGVkTmVyZGxldCI6eyJuZXJkbGV0SWQiOiJhcG0tbmVyZGxldHMub3ZlcnZpZXcifX0=&platform[accountId]=2797319&platform[timeRange][duration]=1800000&platform[$isFallbackTimeRange]=true

Additional Resources

NewRelic.config:

<?xml version="1.0"?> My Application System.IO.FileNotFoundException System.Threading.ThreadAbortException 401 404 System.Threading.WaitHandle:InternalWaitOne System.Threading.WaitHandle:WaitAny **strong text**

Log extract from NewRelic Agent:

Application Logfile:
2020-11-19 15:15:19,250 NewRelic INFO: [pid: 7864, tid: 1] The following assembly will be loaded on-demand: C:\Program Files\New Relic.NET Agent\netframework\extensions\NewRelic.Providers.Wrapper.AspNetCore.dll
2020-11-19 15:15:19,297 NewRelic INFO: [pid: 7864, tid: 1] The following assembly will be loaded on-demand: C:\Program Files\New Relic.NET Agent\netframework\extensions\NewRelic.Providers.Wrapper.Owin.dll
2020-11-19 15:15:19,312 NewRelic INFO: [pid: 7864, tid: 1] The following assembly will be loaded on-demand: C:\Program Files\New Relic.NET Agent\netframework\extensions\NewRelic.Providers.Wrapper.Asp35.dll
2020-11-19 15:15:19,312 NewRelic INFO: [pid: 7864, tid: 1] The following assembly will be loaded on-demand: C:\Program Files\New Relic.NET Agent\netframework\extensions\NewRelic.Providers.Wrapper.Sql.dll
2020-11-19 15:15:19,312 NewRelic INFO: [pid: 7864, tid: 1] Loading extensions of type NewRelic.Agent.Extensions.Providers.IContextStorageFactory from folder: C:\Program Files\New Relic.NET Agent\netframework\extensions
2020-11-19 15:15:20,625 NewRelic INFO: [pid: 7864, tid: 1] Loading extensions of type NewRelic.Agent.Extensions.Providers.Wrapper.IWrapper from folder: C:\Program Files\New Relic.NET Agent\netframework\extensions
2020-11-19 15:15:22,594 NewRelic INFO: [pid: 7864, tid: 1] Application name from web.config or app.config.
2020-11-19 15:15:22,594 NewRelic INFO: [pid: 7864, tid: 1] Your New Relic Application Name(s): PRD-FFE-ContactCentreUpdateProcessor
2020-11-19 15:15:25,219 NewRelic INFO: [pid: 7864, tid: 1] Agent FactFind.ContactCentreUpdateProcessor.exePRD-FFE-ContactCentreUpdateProcessor connected to collector-001.eu01.nr-data.net:443
2020-11-19 15:15:25,328 NewRelic INFO: [pid: 7864, tid: 1] Reporting to: https://rpm.eu.newrelic.com/accounts/2797319/applications/100087099
2020-11-19 15:15:25,422 NewRelic INFO: [pid: 7864, tid: 1] The following events will be harvested every 5000ms: Error events, Custom events, Transaction events
2020-11-19 15:15:25,609 NewRelic INFO: [pid: 7864, tid: 1] Agent fully connected.
2020-11-19 15:15:25,890 NewRelic INFO: [pid: 7864, tid: 1] Reading configuration from “C:\ProgramData\New Relic.NET Agent\newrelic.config”
2020-11-19 15:15:26,250 NewRelic INFO: [pid: 7864, tid: 1] The New Relic .NET Agent v8.29.0.0 started (pid 7864) on app domain ‘FactFind.ContactCentreUpdateProcessor.exe’
2020-11-19 15:15:49,422 NewRelic INFO: [pid: 7864, tid: 2] Metric harvest starting.
2020-11-19 15:15:50,281 NewRelic INFO: [pid: 7864, tid: 2] The New Relic .NET Agent v8.29.0.0 has shutdown (pid 7864) on app domain ‘FactFind.ContactCentreUpdateProcessor.exe’

PID log file:
[Info ] 2020-11-19 15:15:02 Logger initialized.
[Trace] 2020-11-19 15:15:02 New Relic .NET Agent
[Info ] 2020-11-19 15:15:02 Initializing ThreadProfiler
[Info ] 2020-11-19 15:15:02 Found newrelic.config at: C:\ProgramData\New Relic.NET Agent\newrelic.config
[Info ] 2020-11-19 15:15:02 <-- New logging level set: Info
[Info ] 2020-11-19 15:15:02 New Relic .NET Agent v8.29.0.0
[Info ] 2020-11-19 15:15:02 Loading instrumentation from C:\ProgramData\New Relic.NET Agent\extensions
[Warn ] 2020-11-19 15:15:02 No instrumentation files found.
[Info ] 2020-11-19 15:15:02 Loading instrumentation from C:\ProgramData\New Relic.NET Agent\extensions\netframework
[Info ] 2020-11-19 15:15:02 Duplicate instrumentation for [System.Web.Http]System.Web.Http.Controllers.ApiControllerActionInvoker.InvokeActionAsync() was found and will be ignored
[Info ] 2020-11-19 15:15:02 Command line: E:\Scheduled-Tasks\Production\Prod.FactFind.ContactCentreUpdateProcessorEvolution\FactFind.ContactCentreUpdateProcessor.exe
[Info ] 2020-11-19 15:15:02 Enabling instrumentation for this process due to existence of NewRelic.AgentEnabled=true in E:\SCHEDULED-TASKS\PRODUCTION\PROD.FACTFIND.CONTACTCENTREUPDATEPROCESSOREVOLUTION\FACTFIND.CONTACTCENTREUPDATEPROCESSOR.EXE.config.
[Info ] 2020-11-19 15:15:02 Profiler initialized
[Info ] 2020-11-19 15:15:13 Instrumenting method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll, AppDomain: FactFind.ContactCentreUpdateProcessor.exe)[System.Data]System.Data.SqlClient.SqlConnection.Open()
[Info ] 2020-11-19 15:15:13 Instrumenting helper method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll, AppDomain: EE Shared Assembly Repository)[mscorlib]System.CannotUnloadAppDomainException.GetMethodFromAppDomainStorageOrReflectionOrThrow(System.String,System.String,System.String,System.String,System.Type[])
[Info ] 2020-11-19 15:15:13 Instrumenting helper method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll, AppDomain: EE Shared Assembly Repository)[mscorlib]System.CannotUnloadAppDomainException.GetMethodFromAppDomainStorage(System.String)
[Info ] 2020-11-19 15:15:13 Instrumenting helper method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll, AppDomain: EE Shared Assembly Repository)[mscorlib]System.CannotUnloadAppDomainException.GetMethodViaReflectionOrThrow(System.String,System.String,System.String,System.Type[])
[Info ] 2020-11-19 15:15:13 Instrumenting helper method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll, AppDomain: EE Shared Assembly Repository)[mscorlib]System.CannotUnloadAppDomainException.GetTypeViaReflectionOrThrow(System.String,System.String)
[Info ] 2020-11-19 15:15:13 Instrumenting helper method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll, AppDomain: EE Shared Assembly Repository)[mscorlib]System.CannotUnloadAppDomainException.LoadAssemblyOrThrow(System.String)
[Info ] 2020-11-19 15:15:13 Instrumenting helper method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll, AppDomain: EE Shared Assembly Repository)[mscorlib]System.CannotUnloadAppDomainException.StoreMethodInAppDomainStorageOrThrow(System.Reflection.MethodInfo,System.String)
[Info ] 2020-11-19 15:15:21 Instrumenting method: (Module: C:\windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll, AppDomain: FactFind.ContactCentreUpdateProcessor.exe)[System]System.Net.HttpWebRequest.SerializeHeaders()
[Info ] 2020-11-19 15:15:22 Instrumenting method: (Module: C:\windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll, AppDomain: FactFind.ContactCentreUpdateProcessor.exe)[System]System.Net.HttpWebRequest.GetResponse()
[Info ] 2020-11-19 15:15:27 Instrumenting method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll, AppDomain: FactFind.ContactCentreUpdateProcessor.exe)[System.Data]System.Data.SqlClient.SqlCommand.ExecuteReader(System.Data.CommandBehavior,System.String)
[Info ] 2020-11-19 15:15:39 Instrumenting method: (Module: C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll, AppDomain: FactFind.ContactCentreUpdateProcessor.exe)[System.Net.Http]System.Net.Http.HttpClient.SendAsync(System.Net.Http.HttpRequestMessage,System.Net.Http.HttpCompletionOption,System.Threading.CancellationToken)
[Info ] 2020-11-19 15:15:48 Instrumenting method: (Module: C:\windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll, AppDomain: FactFind.ContactCentreUpdateProcessor.exe)[System.Data]System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
[Info ] 2020-11-19 15:15:50 Profiler shutting down
[Info ] 2020-11-19 15:15:50 Profiler shutdown

Hi, @matthew.hirst: The .NET agent is designed to monitor web applications by default. Other types of applications, such as console applications or Windows services, will likely require custom instrumentation. You may find this post helpful:

Thanks Phil, I was trying to avoid doing this, especially as these console applications are not doing anything clever but call API endpoints or run SQL SP in most cases. My question of that is the logs show “Instrumenting method” and then the correct method calls that the applications are running but this is not appearing in APM? If the logs didn’t show this I would agree and we would have tried to use custom instrumentation but the logs do show this so it looks more like it is a configuration issue?

In addition to the logs I have noted a small amount of telemetry appearing in APM for this app. It happens to have been when the console application took longer to process it’s events - circa 20 seconds - this would correspond to this entry in the log files:

“The following events will be harvested every 5000ms: Error events, Custom events, Transaction events”

The question is, how do I get it to log even when the console application runs for less than this time?