serilog / serilog-enrichers-process

The process enricher for Serilog.
Apache License 2.0
30 stars 10 forks source link

Use Assembly name in .Net Core #8

Open bitchkat opened 6 years ago

bitchkat commented 6 years ago

In .Net core apps, they are typically run via "dotnet MyProgram.dll". This means the program name will always use "dotnet" as the program name. It would be really handy if this could be detected and the name of the actual .net core console app could be used.

I hacked up some local mods to effect these changes. Effectively, if the process name is "dotnet" I retrieve the entity dotnet is executing via

System.Reflection.Assembly.GetEntryAssembly().GetName().Name;

As it turns out, .Net standard 1.3 doesn't have the GetEntryAssembly() method, so I modified the project to add a .Net Standard 2.0 to the frameworks and conditionally compile the code above on .NetStandard 2.0.

My visual studio 2017 did some migration on the project so I'll include the csproj file that resulted from that since that is where I had to set up the .Net Standard 2.0 build. dotnetcore-process-name.patch.txt

Numpsy commented 3 years ago

Would this be considered a reasonable feature to have then? (the other changes to the project and targets and such in the attached patch should have already been done now)