开发者

How to log Computer Environment name in log4net?

开发者 https://www.devze.com 2022-12-25 18:38 出处:网络
Does anyone know how to dump environment name in log4net? e.g. <c开发者_开发问答onversionPattern value=\"%date{ISO8601} Server:%property{log4net:HostName} [%-5level] %m\" />

Does anyone know how to dump environment name in log4net?

e.g.

<c开发者_开发问答onversionPattern value="%date{ISO8601} Server:%property{log4net:HostName} [%-5level] %m" />

This will give computer name.


Not sure what do you mean by "environment name", but with log4net contexts you can log anything: logged on user, ip address if dynamic etc.

Not sure how to add it to the e-mail subject, but in the body pattern would be:

<conversionPattern value="%date{ISO8601} Server:%property{environment} [%-5level] %m" />

after you init log4net, call this:

    log4net.GlobalContext.Properties["environment"] =
Environment.GetEnvironmentVariables("EnvironmentName")+"AppName";


It seems you can just add $(COMPUTERNAME) to your conversionPattern. If it is the computername you were looking for?

0

精彩评论

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