//设置web api configuration
public static void Register(HttpConfiguration config)
{
config.Services.Replace(typeof(ITraceWriter), new NLogger());
}
//设置asp.net 应用程序 全局configuration
GlobalConfiguration.Configuration.Services.Replace(typeof(ITraceWriter), new NLogger());
//获取 全局configuration
var writer = GlobalConfiguration.Configuration.Services.GetTraceWriter();
//获取 actionContext 当前configuration
ITraceWriter writer = actionContext.ControllerContext.Configuration.Services.GetTraceWriter();