• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

120
Views
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.

<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. source="MyAwesomeSolution"

Thanks in advance.

2 months ago ·

Santiago Trujillo

1 answers
Answer question

0

You can use any predefined variable or your custom field in the source field.

e.g. 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/EventLog-target

2 months ago · Santiago Trujillo Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.