May 23, 2010 at 9:30 AM
Edited May 23, 2010 at 9:46 AM
You can't use lambda statements in attributes, that's a limitation of .NET framework which only allows use of constants in attributes..
Now as for using adapters it's quite simple..
public class LogAdapter : ILocatorAdapter
public object Resolve(string name)
return LogManager.GetLogger(name ?? "Main");
And then you need to register it as such (note this should obviously be done before it is used):
Resource.RegisterLocatorAdapter((t) => t == typeof(ILog), (t) => new LogAdapter());
That's it you are done. And for greater flexibility see how I pass-through the resource name to match the logger name, which means you can ask for another logger like this:
public class MyViewModel
public MyViewModel([ResolveResource("Critical")] ILog logger)
// use your "Critical" logger
So Above we're getting the "Critical" logger - if we remove the [ResolveResource] attribute then it will default to the "Main" logger. Also, FYI there are two other other ways of doing the same thing.. one using custom attributes based
on ResolveResourceBaseAttribute and other using a custom IResourceLocator..
Hope this helps..