I'm working on an approach to trace logging for my company's VB.NET project. The .NET framework has pretty versatile trace capabilities and I'd like to use what .NET already provides. My company wants to stay away from 3rd party software, so log4net and whatnot is out of the question.
They want to be able to trace the flow of the web application, and using trace sources, listeners, and switches will make this part pretty easy. However, they want me to trace when variables change throughout the program without having to write Trace.Write("i = " & i) every other line in a calculation.
So, any efficient approaches out there to do this?
Your answers are appreciated. Thanks in advance.
I decided to go with making a class. I simply made a TraceVariable Class that had an IntegerChanged event. This way, the developers of other parts of the code, will be able to control how to handle the variable change, if he wanted to do something other than trace it.
Here's the code:
Public Class TraceVariable
Private mInteger As Integer
Public Event IntegerChanged(ByVal mInteger As Integer)
Public Property TraceInteger() As Integer
Get
TraceInteger = mInteger
End Get
Set(ByVal value As Integer)
mInteger = value
RaiseEvent IntegerChanged(mInteger)
End Set
End Property
End Class
Thanks for the answers! As for the this being messy, we're only going to use it for critical variables, so no worries. Tracing in our situation is a necessity and a safety precaution.
Tracing every variable change would quickly become messy and lead to information overload for any but the most trivial of applications.
If there are specific variables that you want to trace the changes in, wrap them in a simple self-rolled Traceable class with accessors that write out to Trace when you do an update.
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