I am writing tracing class to find the execution time of modules/methods. I have a class like this
public class Trace
{
static Dictionary<string, Stopwatch> watches = null;
static Trace()
{
Dictionary<string, Stopwatch> watches = new Dictionary<string, Stopwatch>();
}
public static void Start(string key, string losgMessage)
{
try
{
if (!watches.Keys.Contains(key))
{
Stopwatch watch = new Stopwatch();
watch.Start();
watches.Add(key, watch);
}
}
catch
{
}
}
public static void Stop(string key, Object logMessage, string sessionId)
{
try
{
if (!watches.Keys.Contains(key))
{
Stopwatch watch = watches[key];
watch.Stop();
//log goes here
}
}
catch
{
}
}
}
since wcf is multithreaded environment and the 'watches' static variable scope is application level, If some one(new rqst from the differnt client) tries to execute the same method with same key i will not consider it and trace it. So what would be the best option in this case. Any suggestion would be helpful.
edit : I am current appending sessionId with key. Cant i resolve this issue without session id