[英]how to change the source value of the NLog eventlog target
Is there any possibility to change the source name of NLog.config dynamically if yes can any one please help me.如果是的话,是否有可能动态更改 NLog.config 的源名称,请帮助我。
<targets>
<target xsi:type="EventLog" name="eventlog" layout="${callsite}:${message}" log="Application" **source="MyAwesomeSolution"**/>
this is the source name which i wanna change with parameters coming from other method to NLog.Config file.这是我想用来自其他方法的参数更改为 NLog.Config 文件的源名称。 source="MyAwesomeSolution"
来源="MyAwesomeSolution"
Thanks in advance.提前致谢。
You can use any predefined variable or your custom field in the source field.您可以在源字段中使用任何预定义变量或自定义字段。
eg source="${event-properties:item=customName}"
例如
source="${event-properties:item=customName}"
and in your code, you can fill this value在你的代码中,你可以填写这个值
logger.Info("this event is coming from may {customName}", "my app");
or you can use或者你可以使用
logger.SetProperty("customName", "my app");
or even甚至
logger.WithProperty("customName", "my app").Info("test message");
for more details check out the documentation有关更多详细信息,请查看文档
https://github.com/NLog/NLog/wiki/EventProperties-Layout-Renderer#example https://github.com/NLog/NLog/wiki/EventProperties-Layout-Renderer#example
https://github.com/NLog/NLog/wiki/EventLog-target https://github.com/NLog/NLog/wiki/EventLog-target
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.