can I pass a custom property to NLOG and output to file?

前端 未结 4 962
囚心锁ツ
囚心锁ツ 2021-02-06 05:43

EDIT 4: \"From\" seems to be a reserved word in NLog. Changing it \"FromID\" worked. this is an awesome way to pass variables to NLog and still keep your code clean !!!! TH

4条回答
  •  臣服心动
    2021-02-06 06:17

    This is propably not the best way to do this and not even thread safe but a quick and dirty solution: You could use Environment variables:

    Environment.SetEnvironmentVariable("NLogOptionID", "87");
    logger.Debug("My Name id Ed");
    Environment.SetEnvironmentVariable("NLogOptionID", null);
    

    In your layout, you can use environment variables.

    ${environment:variable=NLogOptionID}
    

提交回复
热议问题