Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
I want to use common trace id. I'm using following code.



public void method1(){
using (new Tracer(Guid.NewGuid().ToString()))
{
//my code
}
}
public void method2(){
using (new Tracer(Guid.NewGuid().ToString()))
{
//my code
}
}

C#
Here guid is my trace id. But different trace id generating for every method call. I want keep it as unique. How to achieve this?. (note : I call method1,method2 from some different client)


What I have tried:

public void method1(){
using (new Tracer(Guid.NewGuid().ToString()))
{
//my code
}
}
public void method2(){
using (new Tracer(Guid.NewGuid().ToString()))
{
//my code
}
}
Posted
Updated 19-Jul-16 4:27am

1 solution

C#
The quickest would be to instantiate your Guid outside of your methods and re-use it. I suggest some more reading on the basics though. Since your update includes mention of a different clients you need to provide more detail of the system. Maybe you could pass the Guid around through the server? Hard to say without some detail.

        Guid myGuidToReuse = Guid.NewGuid();
        public void method1()
        {
            using (new Tracer(myGuidToReuse.ToString()))
            {
                //my code
            }
        }
        public void method2()
        {
            using (new Tracer(myGuidToReuse.ToString()))
            {
                //my code
            }
        }
 
Share this answer
 
v2
Comments
tnkarthi 20-Jul-16 0:44am    
is it possible to use single scope?
G3Coder 20-Jul-16 5:40am    
Hi,

Please provide some details of the system.

G

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900