W
Whidbey Wave
A classic case of writing to a log file each time a particular method
is called for rudimentary performance statistics. Ordinarily the code
below satisfy the requirements:
//Considering EventLogManager to be singleton class defined in system.
public class Foo
{
public void bar()
{
EventLogManager.WriteEntry("Bar method begin; writing Stack
trace");
Debug.WriteLine(Environment.StackTrace.ToString());
// do bar()
//
EventLogManager.WriteEntry("Bar method end");
}
}
I like to factor out the logging aspect at method level. To this I
created a new attribute class:
[AttributeUsage(AttributeTargets.Method)]
Class EventLogAttribute:Attribute
{
///TODO: Don't know where to write code for method begin
///and method end.
public EventLogAttribute()
{
Debug.WriteLine(Environment.StackTrace.ToString());
}
}
public class Foo
{
[EventLog()]
public void bar()
{
// do bar()
}
}
The desired functionality is that every time the method bar() is
getting executed , it should do following:
1. Before executing the code of do bar(), it should write message "bar
method begins" and then the stack trace
2. After executing the method do bar() . it should write message "bar
methods ends"
My conclusion on trial n errors:
I may require to inherit not directly from Attribute, but some other
child class of attribute.
I saw on using ObjectContext, the attribute constructor gets called
whenever the object(on which the attribute is applied) is created.
I would like to get suggestions, before i fall back to ordinary
tactics.
Have a nice day...
is called for rudimentary performance statistics. Ordinarily the code
below satisfy the requirements:
//Considering EventLogManager to be singleton class defined in system.
public class Foo
{
public void bar()
{
EventLogManager.WriteEntry("Bar method begin; writing Stack
trace");
Debug.WriteLine(Environment.StackTrace.ToString());
// do bar()
//
EventLogManager.WriteEntry("Bar method end");
}
}
I like to factor out the logging aspect at method level. To this I
created a new attribute class:
[AttributeUsage(AttributeTargets.Method)]
Class EventLogAttribute:Attribute
{
///TODO: Don't know where to write code for method begin
///and method end.
public EventLogAttribute()
{
Debug.WriteLine(Environment.StackTrace.ToString());
}
}
public class Foo
{
[EventLog()]
public void bar()
{
// do bar()
}
}
The desired functionality is that every time the method bar() is
getting executed , it should do following:
1. Before executing the code of do bar(), it should write message "bar
method begins" and then the stack trace
2. After executing the method do bar() . it should write message "bar
methods ends"
My conclusion on trial n errors:
I may require to inherit not directly from Attribute, but some other
child class of attribute.
I saw on using ObjectContext, the attribute constructor gets called
whenever the object(on which the attribute is applied) is created.
I would like to get suggestions, before i fall back to ordinary
tactics.
Have a nice day...