Your question is a bit hard to grok. I think you want to log the name of the instance class or method...
If you want strong typing, I think you need to use reflection. You could of course add a string name to each class that can be logged but that is brittle code and someone later on will hate you for it. You see this style in languages that don't easily support reflection but I'd recommend against that in a language like C#.
So on to a solution:
Is your logging method called from inside the instance? If so, we can use reflection to get the name of the calling method and lots of other information.
If yes, then something like this might work for you:
class MyRequest: IRequest {
// other interface implementation details omitted
public void SetProfiles(Profile p) {
if(HasUglyPicture(p)) {
MyLogger.LogError(String.Format(
"User {0} update attempted with ugly picture", p.UserName)
throw new Exception("Profile update failed due to ugly picture!");
}
}
class MyLogger : ILogger {
// other logger details omitted
public void LogError(string errorMsg) {
// here's where you get the method name
// http://www.csharp-examples.net/reflection-calling-method-name/
StackTrace stackTrace = new StackTrace();
MyLogOutputStream.Write(stackTrace.GetFrame(1).GetMethod().Name);
MyLogOutputStream.WriteLine(errorMsg);
}
}
This stack overflow question might help:
How I can get the calling methods in C#
This website has the code snippet that the two important lines are based on:
http://www.csharp-examples.net/reflection-calling-method-name/