views:

137

answers:

5

I have some .net apps running that I need to monitor for example, then MethodA is called in App1, my monitor app should detect this. I have a lot of running apps and the solution proposed here is to recompile all those apps and include a new line in the desired methods that we want to monitor. I want to do this only if there is absolutely no way. So did anybody ever done something like this? Basically, I need to create a new app that when I click a button on it, it will tell me: MethodA was called in App1, in real time...

thanks!

A: 

System.Diagnostics.PerformanceCounter is a good place to start. You can create new counters that can be viewed in the Performance control panel applet. They're a little confusing at the start, but when you realize average counters need two components to calculate a percentage it gets a lot easier.

Will
A: 

I don't know if .NET has a matching mechanism, but Java allows you to specify an agent JAR file, namely a class that is notified/invoked when each class is loaded. Then, via instrumentation/bytecode manipulation, you could intercept such method calls. Perhaps you can replace the class loader in some way in .NET. not sure.

Shachar
I'm pretty sure you can do so; but I believe you have to do it from unmanaged code.
TraumaPony
A: 

Reflection is what you are looking for in .NET, but I am not sure of the implementation details behind what you want to do.

Geoffrey Chetwood
+3  A: 

There are several ways you could do this. One is to use log4Net, 'sprinkle' your methods with calls to log4Net's write methods. You can choose a variety of logging appenders (destinations) such as email or a database, but a less known tip is to download the standalone program, DebugView (SysInternals -> now Microsoft) which listens for the default messages.

Mitch Wheat
Sounds like @Bruno wants logging. He should use log4net and grab himself a copy of Chainsaw from apache. UdpAppender in the app.config and suddenly you can watch all the logging in real time. It's great.
Hamish Smith
A: 

The PostSharp deliver way, how to edit compiled .net code. The editation is written in C# code which is compiled ( attributes ) or by configuration code. Thay have a mechanism, which can log ( or populate or anything else ) a method/event calling and much more.

I think, this is tool, you need.

TcKs