.NET variable tracking package
-
Hi, I have a long-running application that that periodically outputs the values of many internal fields/variables to a log file. These variables used to all live in one class, but as the application grew and functionality was added, they became spread out across classes. The hack-ish solution is to have globally accessible references to the instances of the classes in question, with each class having public properties for the variables. I feel that this is ugly and breaks OO abstraction. Furthermore, this setup doesn't fix the base problem of seeing when/where things go wrong. Once I see an exception I have to filter through lots of logs to find any evidence of inconsistent state. What I really want is some kind of global statistics tracking package, where I could do something like the following:
Statistics.AddValue("average.requests.time", 0.0); Statistics["requests.served"]+= 1.5; Predicate p = delegate(float val) { return val > 1; }; Statistics.AddConditionalListener("requests.served", p, delegate() { Console.WriteLine("why so slow?"); } );
Basically, a class/package that would store have a name->value mapping, have nice update syntax with operator overloading, and allow you to add listeners for conditions you specify. Oh, and allow you to use a value of any base type, using generics =). Is there something like this out there? Or, are there classes built into the .NET framework that would let me do this easily (e.g. however conditional breakpoints work?). -
Hi, I have a long-running application that that periodically outputs the values of many internal fields/variables to a log file. These variables used to all live in one class, but as the application grew and functionality was added, they became spread out across classes. The hack-ish solution is to have globally accessible references to the instances of the classes in question, with each class having public properties for the variables. I feel that this is ugly and breaks OO abstraction. Furthermore, this setup doesn't fix the base problem of seeing when/where things go wrong. Once I see an exception I have to filter through lots of logs to find any evidence of inconsistent state. What I really want is some kind of global statistics tracking package, where I could do something like the following:
Statistics.AddValue("average.requests.time", 0.0); Statistics["requests.served"]+= 1.5; Predicate p = delegate(float val) { return val > 1; }; Statistics.AddConditionalListener("requests.served", p, delegate() { Console.WriteLine("why so slow?"); } );
Basically, a class/package that would store have a name->value mapping, have nice update syntax with operator overloading, and allow you to add listeners for conditions you specify. Oh, and allow you to use a value of any base type, using generics =). Is there something like this out there? Or, are there classes built into the .NET framework that would let me do this easily (e.g. however conditional breakpoints work?).Sounds to me like a use for several of the windows application blocks in the Enterprise library, specifically the logging application block and maybe some custom code built on that. Also maybe making use of performance counters? http://msdn2.microsoft.com/en-us/library/aa480453.aspx[^]
-
Sounds to me like a use for several of the windows application blocks in the Enterprise library, specifically the logging application block and maybe some custom code built on that. Also maybe making use of performance counters? http://msdn2.microsoft.com/en-us/library/aa480453.aspx[^]
Hi Ray, I couldn't see anything useful in the Enterprise library, but I found information about performance counters (http://www.codeproject.com/KB/dotnet/perfcounter.aspx[^]) and I think they are what I need. I'll try them out and let you know - thanks for the tip.
-
Hi, I have a long-running application that that periodically outputs the values of many internal fields/variables to a log file. These variables used to all live in one class, but as the application grew and functionality was added, they became spread out across classes. The hack-ish solution is to have globally accessible references to the instances of the classes in question, with each class having public properties for the variables. I feel that this is ugly and breaks OO abstraction. Furthermore, this setup doesn't fix the base problem of seeing when/where things go wrong. Once I see an exception I have to filter through lots of logs to find any evidence of inconsistent state. What I really want is some kind of global statistics tracking package, where I could do something like the following:
Statistics.AddValue("average.requests.time", 0.0); Statistics["requests.served"]+= 1.5; Predicate p = delegate(float val) { return val > 1; }; Statistics.AddConditionalListener("requests.served", p, delegate() { Console.WriteLine("why so slow?"); } );
Basically, a class/package that would store have a name->value mapping, have nice update syntax with operator overloading, and allow you to add listeners for conditions you specify. Oh, and allow you to use a value of any base type, using generics =). Is there something like this out there? Or, are there classes built into the .NET framework that would let me do this easily (e.g. however conditional breakpoints work?).This might be a different approach to the problem, but... What immediately comes to mind is the use of some custom attributes. You might also want to check out the Spring.NET framework. There's a lot you could do with some of the functionality in that framework. This very much sounds like a cross-cutting concern, for which aspect-oriented programming would be well suited. BW