how to get name of node on which my code is executing in azure fabric service?

azure, azure-service-fabric, c#

Solution

Use the NodeContext property of the ServiceContext.

So, given the context of a service (either stateful or stateless) or actorservice you can call `context.NodeContext.NodeName` to retrieve the node name.

The `ServiceContext` has a lot of oher properties as well that can be useful for logging purposes.

For a complete example of getting node and service details see this repo.

Problem

How can I get the name of the machine on which my code is running in a Azure Fabric Cluster for logging purposes? I am running a c# code in a fabric cluster with some nodes. I would like to log some information along with the machine name. I am using FabricRuntime, but it is not helping me. What is the best way to do this ? Thanks.

Original source