开发者

Send multiple params into log4net

开发者 https://www.devze.com 2023-02-13 07:14 出处:网络
I\'m trying to send arbitrary arguments into log4net at runtime.Is it possible to define parameters on the fly and send them in?I know you can define global params like this:

I'm trying to send arbitrary arguments into log4net at runtime. Is it possible to define parameters on the fly and send them in? I know you can define global params like this:

log4net.GlobalContext.Properties["MyColumn"] = "MyValue"; 

but I'm thinking 开发者_如何学Pythonmore along the lines of:

myArrayOfCoolStuff["IP"] = "127.0.0.1";
myArrayOfCoolStuff["UserName"] = "jbleaux";
log.Error(myArrayOfCoolStuff);

Given how log4net tends to fail silently when you give it garbage, I'm hoping to find expertise instead of just trying it. Any suggestions on how to do this?


Have a look at this tutorial and in particular the part "Calculated Context Values". You could create a class that accepts your parameters and writes them in whatever format you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消