Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / November 2006

Tip: Looking for answers? Try searching our database.

Tracking method calling

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stepanfryd@msn.com - 14 Nov 2006 15:17 GMT
Hi all,

I have a question about tracking of method calls. I would like to track/log
methods in code during runtime. I thought that I can write custom attribute
which I will use in method which call I want to log and in constructor of
the attribute I will write logging functionality. But this doesn't work. No
code in attribute class is executed.

Any idea how to solve this problem?

Stepan

---------------------------------------------------------
Example:

[AttributeUsage(AttributeTargets.Method)]
public class LoggerAttribute : System.Atribute {
   public LoggerAttribute () {
       // here is code for logging
   }
}

Usage:
public class TestLoggerClass {

   [Logger]
   public void DoSomething() {
       // here is some cod
   }
}

public class TestProgram {
   public static void Main(string[] params) {
       TestLoggerClass x = new TestLoggerClass();

       // I want to log method calling when I do next row. But it doesn't
work
       x.DoSomething();
   }
}
Patrice - 14 Nov 2006 15:27 GMT
Else have you checked when the attribute is initialized ? IMO it would be
rather look like an interception scheme that I believe can be done but
perhaps with unmanaged code if I remember (used for profilers ?). What
benefit do you expect from the custom attribute method ? For now, my first
thought would be likey to look at System.diagnostics.Trace capabilities.

Signature

Patrice

> Hi all,
>
[quoted text clipped - 36 lines]
>    }
> }
stepanfryd@msn.com - 14 Nov 2006 16:26 GMT
Hi,

System.Diagnostics.Trace is similar. But I don't want to write code
"Trace.WriteBlahBlah()". I want write only Attribute on method and maximaly
specified trace category.

E.g.
[Logger("Category1")]
public void DoSomething1()  {}

[Logger("Category2")]
public voiod DoSomething2() {}

I expect les code to use it. My idea is to use EntLibs Logging blog and
implemented it into attribute.

Stepan

> Else have you checked when the attribute is initialized ? IMO it would be
> rather look like an interception scheme that I believe can be done but
[quoted text clipped - 42 lines]
>>    }
>> }
Patrice - 14 Nov 2006 18:51 GMT
In addition to Michael answer,
http://geekswithblogs.net/imilovanovic/articles/11589.aspx could be a
starting point to several ideas.

Make sure tracing calls is the only thing you'll need (else you'll liekly
need to go back to the "usual" trace mechanism).

Signature

Patrice

> Hi,
>
[quoted text clipped - 61 lines]
>>>    }
>>> }
Michael Nemtsev - 14 Nov 2006 18:30 GMT
Hello stepanfryd@msn.com,

BTW, I recomment to look at this lib (free)
http://www.postsharp.org/

> I have a question about tracking of method calls. I would like to
> track/log methods in code during runtime. I thought that I can write
> custom attribute which I will use in method which call I want to log
> and in constructor of the attribute I will write logging
> functionality. But this doesn't work. No code in attribute class is
> executed.

---
WBR,
Michael  Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.