Log4PostSharp - How to supress code generation for iterators

Support of Log4PostSharp

Log4PostSharp - How to supress code generation for iterators

Postby tbaer on Tue May 27, 2008 5:38 pm

Greetings,

I'm working with Postsharp since a few days now but I'm impressed how powerful it is. :geek: Great work ;)

Now I want to simplyfy my logging mechanism and found Log4PostSharp. Also great code but I encountered a problem with iterators.

My Intention is to activate code generation for the whole classes an suppress it for a couple one. One of the classes where I want to suppress logging contains an iterator as returntype (IEnumerable<T>) and yield return.
For that the compiler generates an anonymous generic class and Log4PostSharp injects logging for that (seen in .NET Reflector).

My question now is how to I suppress the code injection for that anonymous class?
For the surrounding classes it works pretty well with Log(AttributeExclude = true) but not for that private generated class ...
I also testet Log(AttributeTargetTypes="Log4PostSharp.Test.Testclass*", AttributeExclude = true).

The attached file contains a testclass placed in the Log4PostSharp.Test-Project of Log4PostSharp.

Is there a way to supress code generation?

torsten
You do not have the required permissions to view the files attached to this post.
"Things should be as simple as possible, but no simpler" A. Einstein
tbaer
 
Posts: 2
Joined: Tue May 27, 2008 5:10 pm
First Name: Torsten
Last Name: Bär

Re: Log4PostSharp - How to supress code generation for iterators

Postby gfraiteur on Tue May 27, 2008 8:53 pm

What I would do is to patch this project to add some more logic: if the method is decorated with the [CompilerGenerated] custom attribute, we don't trace it.

You could propose it to Michal, the author. (Use for instance private messaging: ucp.php?i=pm&mode=compose&u=219).
Gael Fraiteur, project leader
gfraiteur
Site Admin
 
Posts: 834
Joined: Tue Dec 18, 2007 3:09 pm
First Name: Gael
Last Name: Fraiteur
Company: postsharp.org

Re: Log4PostSharp - How to supress code generation for iterators

Postby herrmic on Thu May 29, 2008 12:07 am

Hi,

this is something that I have missed, thank you for the report. I'll work on this during the weekend.

@Gael: thank you for the advice, your solution looks like the right one. Do you know if this attribute is placed automatically on all classes/methods generated by the compiler (iterators, anonymous delegates)?
Regards,
Michal Dabrowski
http://herrmic-coding.blogspot.com/
herrmic
 
Posts: 20
Joined: Sat Jan 12, 2008 4:55 pm
First Name: Michal
Last Name: Dabrowski

Re: Log4PostSharp - How to supress code generation for iterators

Postby gfraiteur on Thu May 29, 2008 7:59 am

Yes, the compiler always puts this custom attribute on auto-generated artifacts.

I would also add a property to your custom attribute to force logging even if it is compiler-generated.

G
Gael Fraiteur, project leader
gfraiteur
Site Admin
 
Posts: 834
Joined: Tue Dec 18, 2007 3:09 pm
First Name: Gael
Last Name: Fraiteur
Company: postsharp.org

Re: Log4PostSharp - How to supress code generation for iterators

Postby gfraiteur on Thu May 29, 2008 8:04 am

I created a new forum for the project Log4PostSharp. Michal, could you subscribe to receive notifications on all posts of this forum?

Thanks,

Gael
Gael Fraiteur, project leader
gfraiteur
Site Admin
 
Posts: 834
Joined: Tue Dec 18, 2007 3:09 pm
First Name: Gael
Last Name: Fraiteur
Company: postsharp.org

Re: Log4PostSharp - How to supress code generation for iterators

Postby herrmic on Sat May 31, 2008 10:32 am

Sure, subscription already done :) Thanks for the separate forum.

I'll work on the issue today or tomorrow.
Regards,
Michal Dabrowski
http://herrmic-coding.blogspot.com/
herrmic
 
Posts: 20
Joined: Sat Jan 12, 2008 4:55 pm
First Name: Michal
Last Name: Dabrowski

Re: Log4PostSharp - How to supress code generation for iterators

Postby herrmic on Mon Jun 02, 2008 12:35 am

Hi,

I've added IncludeCompilerGeneratedCode property to the Log attribute.

By default, methods decorated with CompilerGeneratedAttribute are not woven. This also applies to methods declared in types that are decorated with the attribute.
Regards,
Michal Dabrowski
http://herrmic-coding.blogspot.com/
herrmic
 
Posts: 20
Joined: Sat Jan 12, 2008 4:55 pm
First Name: Michal
Last Name: Dabrowski

Re: Log4PostSharp - How to supress code generation for iterators

Postby tbaer on Mon Jun 09, 2008 10:00 pm

Works great now ;) Thanks for quick response!
"Things should be as simple as possible, but no simpler" A. Einstein
tbaer
 
Posts: 2
Joined: Tue May 27, 2008 5:10 pm
First Name: Torsten
Last Name: Bär


Return to Log4PostSharp