1

I would like to show line numbers for my trace messages.

Example Trace: SomeMethodUsingPostSharpOnEntry (Line:74): Done doing something.

I cannot use stackframe/trace (runtime reflection solution & not sure if pdb's will be distributed).

Already looked at Microsoft options (http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/6a7b021c-ec81-47c5-8f6a-2e280d548f3f) and pdb based solutions (How can I include line numbers in a stack trace without a pdb?).

Is there any way to get/make a LINE macro equivalent using Postsharp or otherwise?

Community
  • 1
  • 1
saikatax
  • 13
  • 2

2 Answers2

3

It's not much help now, but C# 5 will have this via "caller info attributes". Read the C# team blog post about C# 5 and VS 11 beta for more information, or see the docs for these attributes:

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

There is a hidden option in PostSharp for doing that. First, you have to emit the error message using the proper overload of Message.Write; the one accepting a MethodInfo for instance (or another MessageLocation).

Then, you need to enable the experimental option in Visual Studio options / PostSharp / Experimental.

Finally, restart Visual Studio.

This should cause PostSharp resolve the location of the MethodInfo you pass as an argument. This feature relies on Visual Studio and may be slow, this is why it is experimental.

Gael Fraiteur
  • 6,759
  • 2
  • 24
  • 31