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.
In this article A Service Fabric cluster is a network-connected set of virtual or physical machines into which your microservices are deployed and managed. A machine or VM that's part of a cluster is called a node.
A single Service Fabric node type/scale set can not contain more than 100 nodes/VMs. To scale a cluster beyond 100 nodes, add additional node types.
Service Fabric has the concept of seed nodes. These are nodes that maintain the availability of the underlying cluster. Seed nodes help to ensure that the cluster stays up by establishing leases with other nodes and serving as tiebreakers during certain kinds of failures.
Copy or download the standalone package for Service Fabric for Windows Server to the VM/machine and unzip the package. Run PowerShell with elevated privileges and go to the location of the unzipped package. Run the AddNode. ps1 script with the parameters describing the new node to add.
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.
FabricRuntime.GetNodeContext().NodeName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With