# Dotnet core WPF application - how to get APM traces

**URL:** <https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035>\
**Category:** APM\
**Tags:** dotnet, language-clients\
**Created:** [September 23, 2022, 3:51pm UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035 "2022-09-23T15:51:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SaEd](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@SaEd](https://discuss.elastic.co/u/SaEd)\
**Post date:** [September 23, 2022, 3:51pm UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035/1 "2022-09-23T15:51:42Z")

</div>

Hello all,  
I have a .net core WPF application (_not_ [asp.net](http://asp.net) core). I'm also using Serilog for logging.  
From Elastic Stack: Fleet with integrations: APM 8.4.2, Custom Log 1.0.0, System 1.16.2  
Also using Elastic-agent 8.4 running on my laptop

I can't seem to get APM trace ids in my logs. Is this possible for a _none_ [asp.net](http://asp.net) application?

My setup looks like this

```auto
private IHostBuilder CreateHostBuilder()
        {
            return Host.CreateDefaultBuilder()
                .UseAllElasticApm()
                .ConfigureServices((hostContext, services) =>
                {
                    //Add you business services
                    services.AddLogging(loggingBuilder =>
                        loggingBuilder
                            .AddSerilog(dispose: true)
                            .AddConsole());
                    services.AddScoped<MainWindow>();
                    services.AddScoped<MainWindowViewModel>();
               });
        }

```

And logger setup

```auto
Log.Logger = new LoggerConfiguration()
                .MinimumLevel.ControlledBy(levelSwitch)
                .MinimumLevel.Override("Microsoft.NetCore", LogEventLevel.Warning)
                .MinimumLevel.Override("Elastic.Apm", LogEventLevel.Warning)
                .Enrich.FromLogContext()
                .Enrich.WithElasticApmCorrelationInfo()
                .WriteTo.Console(outputTemplate: "[{ElasticApmTraceId} {ElasticApmTransactionId} {Message:lj} {NewLine}{Exception}")
                .Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
                    .WithDefaultDestructurers())
                .WriteTo.File(new ElasticsearchJsonFormatter(), $"C:\\Temp\\ES\\logES.json", LogEventLevel.Information, fileSizeLimitBytes: 100000, null, false, false, null, RollingInterval.Hour)
                .CreateLogger();

```

Thank you

---

<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:** [September 26, 2022, 8:21am UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035/2 "2022-09-26T08:21:39Z")

</div>

Hi @SaEd,

may I ask you to elaborate on your use case and provide me with additional information, please?

- Are you using the agent's `Tracer` API (see [here](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html#api-tracer-api)) for creating transactions in your WPF application?
  - Or are you using technologies (e.g. HTTP Client, MongoDB) that you expect to be monitored out-of-the-box?

- Which Elastic NuGet packages are you using in your application?
- Do see your WPF application show up at all on your APM server or is this problem only about logging enrichment?

Thanks,  
Wolfgang

---

<div class="post-metadata">

**Author:** ![SaEd](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@SaEd](https://discuss.elastic.co/u/SaEd)\
**Post date:** [September 26, 2022, 4:14pm UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035/3 "2022-09-26T16:14:37Z")

</div>

Hi @Wolfgang_Ziegler ,  
I would like to use Serilog to capture my code instrumentation. Something similar to

```auto
_log.Information("{objectName} {TimeTaken} {Measuring} {Count} {SPROC}",
                "SomeUtil", sw.ElapsedMilliseconds, "MyMethod",
                myList.Count.ToString(), MY_SPROC);

```

This shows up in Elastic Search but not in APM. I'm using the Tracer API in my top-level method as in

```auto
Elastic.Apm.Agent.Tracer
                .CaptureTransaction("Top Level Thread", ApiConstants.TypeRequest, (t) =>
                {
                    someUtil.MyMethod();
                    _log.Information("{className} {TimeTaken} {Measuring}", GetType().Name, sw.ElapsedMilliseconds, "someUtil.MyMethod");
                });

```

This one shows up in APM logs and it has the Trace Id populated. But, all other log statements in my "someUtil.MyMethod()" call do not. I was expecting everything within the same transaction to be logged to APM?

Elastic.Apm.NetCoreAll: 1.17.0  
Elastic.Apm: 1.17.0  
Elastic.Apm.Extensions.Logging: 1.17.0  
Elastic.Apm.SqlClient: 1.17.0  
Elastic.Apm.SerilogEnricher: 1.5.3  
Elastic.CommonSchema.Serilog: 1.5.3  
Serilog.Formatting.Elasticsearch: 8.4.1

---

<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:** [September 27, 2022, 12:27pm UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035/4 "2022-09-27T12:27:14Z")

</div>

Hi @SaEd,

I tried to reproduce your problem but unfortunately to no avail.

Are you using the same `ILogger` object in `someUtil.MyMethod` as directly in the `CaptureTransaction` lambda?

Could you try (just for testing) passing the `_log` object as an argument to `someUtil.MyMethod` and see if the logs show up then if you use this one?

Another sanity check would be to print the values of:

- `Agent.Tracer.CurrentTransaction.Id`
- `Agent.Tracer.CurrentTransaction.TraceId`

in all locations where you write logs and expect correlations with APM transactions.

If `CurrentTransaction` is not `null` then those logs must be enriched.

---

<div class="post-metadata">

**Author:** ![SaEd](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@SaEd](https://discuss.elastic.co/u/SaEd)\
**Post date:** [September 29, 2022, 8:17pm UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035/5 "2022-09-29T20:17:53Z")

</div>

Thanks @Wolfgang_Ziegler , all the above is correct and available.  
Somehow everything started to work yesterday. I'm not sure what changed.

The logging statement in question is in a sperate dll, so I included a few NuGet packages to the project and that's when I noticed it to work. But, then I removed them all, did a clean build but it is still working fine. I'm puzzled?

---

<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:** [September 30, 2022, 5:44am UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035/6 "2022-09-30T05:44:49Z")

</div>

Thanks for the update @SaEd,  
since we cannot reproduce the issue anymore, I will close this question.  
Feel free to reach out again, in case the problem shows up again.  
Cheers,  
Wolfgang

---

<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:** [September 30, 2022, 5:46am UTC](https://discuss.elastic.co/t/dotnet-core-wpf-application-how-to-get-apm-traces/315035/7 "2022-09-30T05:46:00Z")

</div>


