我有一个消息处理程序,在Azure中运行以下签名:
public static void DispatchQueueMessage([QueueTrigger("bq")] string msg,
TextWriter tw)
Run Code Online (Sandbox Code Playgroud)
我想配置log4net以使用提供的TextWriter.
如果这一般不可能,我绝对会选择使用标准格式输出的单个ILog实例!
我最终做了(如下):
ILog log = LogManager.GetLogger(name);
var appender = new TextWriterAppender();
appender.Writer = tw;
appender.Threshold = log4net.Core.Level.Debug;
DynamicPatternLayout layout = new DynamicPatternLayout();
layout.ConversionPattern = "%d [%t] %-5p %m%n";
layout.ActivateOptions();
appender.Layout = layout;
appender.ActivateOptions();
((log4net.Repository.Hierarchy.Logger) log.Logger).AddAppender(appender);
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Configured = true;
return log;
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
鉴于以下设置:
def mapper(f):
def wrapper(items):
for x in items:
yield f(x)
wrapper.__name__ = f.__name__ # This has no effect!
return wrapper
@mapper
def double(x):
return x * 2
Run Code Online (Sandbox Code Playgroud)
装饰器按预期工作:
>>> [x for x in double([1,2,3])]
[2, 4, 6]
Run Code Online (Sandbox Code Playgroud)
然而,它__name__不是double所希望的:
>>> double([1,2]).__name__
"wrapper"
Run Code Online (Sandbox Code Playgroud)
是否可以强制生成器的名称?或者,是否可以在生成器对象中挖掘并检索名称double?