this question is similar to How do I log a custom field in NLog to database? , but in my case I would like to log the same value in each log. Typically this will be a hardcoded component identifier e.g. MAC adress, which we read once at start and want to have inserted automatically into all logs.
If I follow the quoted answer, I could do something like: LogEventInfo theEvent = new LogEventInfo(logLevel, "", message); theEvent.Properties["ComponentID"] =MACADDRESS;`
log.Log(theEvent);
but I would like to avoid having to do this for each log. Is there some way to have this value automatically by specifying a layout for the file logger with perhaps an nlog parameter something like:
<parameter name="@ComponentID" layout="${ComponentID}"/>
I would then set the value somewhere in my code