# In a .NET Console app, can I flush data instead of waiting flush interval?

**URL:** <https://discuss.elastic.co/t/in-a-net-console-app-can-i-flush-data-instead-of-waiting-flush-interval/319174>\
**Category:** APM\
**Tags:** dotnet, language-clients\
**Created:** [November 17, 2022, 10:51am UTC](https://discuss.elastic.co/t/in-a-net-console-app-can-i-flush-data-instead-of-waiting-flush-interval/319174 "2022-11-17T10:51:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glacasa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glacasa/32/113458_2.png) [@glacasa](https://discuss.elastic.co/u/glacasa)\
**Post date:** [November 17, 2022, 10:51am UTC](https://discuss.elastic.co/t/in-a-net-console-app-can-i-flush-data-instead-of-waiting-flush-interval/319174/1 "2022-11-17T10:51:00Z")

</div>

I'm trying to monitor a console app (automatically run every hour) in .NET

The app is built on an HostBuilder, I have called `.UseAllElasticApm()` and `.UseConsoleLifetime()` on it, and I make a transaction by code :

```auto
var transaction = Elastic.Apm.Agent.Tracer.StartTransaction("ConsoleAppRunning", ApiConstants.TypeRequest);

try {
    await RunCode();
}
catch (Exception ex){
    transaction.CaptureException(ex);
}
finally{
    transaction.End();
}

```

The app closes just after the finally.

This code worked on my dev machine, and I could see data appear on APM.

But once built in `Release` mode and deployed to Production server, I could see the service in Kibana with Environment Production, but no data in it.

After searching a while, I think the problem is the [flush interval](https://www.elastic.co/guide/en/apm/agent/dotnet/current/config-reporter.html#config-flush-interval) set to 30s by default

I changed the value to 1s, and added a Task.Delay at the end of the console app, and now I see the transactions in Kibana.

But I don't like this solution, isn't there a way to force flush when I know my app is about to close, and wait for it to be done ?

Also, one more question :  
for the transaction type, I use `ApiConstants.TypeRequest`, can I use any other string here, or am I limited to the values in `ApiConstants` ?

---

<div class="post-metadata">

**Author:** ![Wolfgang\_Ziegler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfgang_ziegler/32/109929_2.png) [@Wolfgang\_Ziegler](https://discuss.elastic.co/u/Wolfgang_Ziegler)\
**Post date:** [November 21, 2022, 5:44pm UTC](https://discuss.elastic.co/t/in-a-net-console-app-can-i-flush-data-instead-of-waiting-flush-interval/319174/2 "2022-11-21T17:44:42Z")

</div>

Hi @glacasa,

unfortunately, a `Flush` API is not available yet.  
Here is a GitHub issue if you want to track the progress of that feature: [Agent API to flush all the queued events · Issue #288 · elastic/apm-agent-dotnet · GitHub](https://github.com/elastic/apm-agent-dotnet/issues/288)

For transition types, you can use an arbitrary strings.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 12, 2022, 1:44pm UTC](https://discuss.elastic.co/t/in-a-net-console-app-can-i-flush-data-instead-of-waiting-flush-interval/319174/3 "2022-12-12T13:44:52Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
