EDIT: I hadn't seen the bit in the question saying you wanted it at execution time.
The problem about writing out data execution time is that you need to know where to write it. What logging does your application use in general? Use the same form of logging as that, basically.
I would still favour the compile-time option listed below, however - you can turn off specific warnings in the compatibility layer using #pragma warn disable/restore
, but it'll make it a lot easier to spot the problems than hoping someone reads a log file...
Old answer
Use the [Obsolete]
attribute on any type or member. You can decide whether this should end up being a warning or an error. For example:
using System;
class Test
{
static void Main()
{
OldMethod();
BadMethod();
}
[Obsolete("Use something else instead")]
static void OldMethod() {}
[Obsolete("This would destroy your machine!", true)]
static void BadMethod() {}
}
Compiling this gives:
Test.cs(7,9): warning CS0618:
'Test.OldMethod()' is obsolete: 'Use
something else instead'
Test.cs(8,9):
error CS0619: 'Test.BadMethod()' is
obsolete: 'This would destroy your
machine!'
Ideally, the message should explain what the effects of continuing to use the method would be, and the suggested alternative.