Error Logging for console application using .net agent

I want to log error using console application in C#. I have put following setting in my app.config
add key=“NewRelic.AgentEnabled” value=“true” />
add key=“NewRelic.AppName” value=“TestConsole” />
and my code is log error using NoticeError method as following

NewRelic.Api.Agent.NewRelic.NoticeError(new Exception(“Hi error”));

and also able to see TestConsole application in my dashboard but. When click on error link i didn’t see any error. I have also installed all component of .net agent during installation.

Please help me out.
Thanks in advance


It sounds like you are trying to get the .NET agent to monitor a non-IIS (console/background/worker) application. In order to do this you have to define custom instrumentation and custom transactions that let the agent know what part(s) of your application you want to monitor.

You should check out this forum post. It will walk you through the whole process.

Let us know how it goes.

Thanks for reply.
I followed steps of above mention links . And able to see performance and transaction in my new relic dashboard(application type non-iis). But my main issue is that I have to log my handled error using NewRelic.Api.Agent.NewRelic.NoticeError(new Exception(“Hi error”)); method. I tired with same steps but when i click on error link it is showing nothing.
But when i call error logging method in multi loop based on timer then some time its logging error message.
Are there any constraint for console application that application should run for minimum time.

I am stuck please help.

HI Guarav1,

Yes, there is a minimum time that the application must run in order for the agent to collect data and send it to New Relic. The agent’s “harvest cycle” is one minute. If the application does not run for at least this amount of time, any data collected will be lost when the service (and by extension, the agent) shuts down.

If your application runs for less than one minute, you can configure the agent to halt the service from shutting down long enough for it to send the data it has collected so far. To do this, you need to set the sendDataOnExit and sendDataOnExitThreshold service elements in your newrelic.config file.

The sendDataOnExit element tells the agent to hold the shutdown of the process until it can send off the data it has collected.

The sendDataOnExitThreshold element sets the minimum amount of time, in milliseconds, that the application must run before the sendDataOnExit requirement is enforced.

For example, if you wanted to set the agent to send it’s data on exit if your application ran for at least one second, you would edit the newrelic.config file <service> element to resemble the following:

<service licenseKey="YOUR_LICENSE_KEY" [etc...] sendDataOnExit="true" sendDataOnExitThreshold="1000" [etc...] >

Once these configurations are in place, restart your host service (WCF, IIS, etc.) to force the agent to pick up the changes.

Hope this helps.