如何使用垂直字段而不是水平列进行记录? [英] How to log using vertical fields instead of horizontal columns?

查看:74
本文介绍了如何使用垂直字段而不是水平列进行记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NLog.EventLog目标,并希望使用API​​以垂直字段格式记录事件.

I'm using the NLog.EventLog target, and using the API I wish to log an event in vertical-field format.

它可能看起来像这样:

Method:  ServiceBase.Manager.StartService()
Message: The service started successfully.
Result:  The service is listening for requests.

这可能吗?

推荐答案

当然,是这样的:

 <target name="file" xsi:type="File"
         layout="Method: ${callsite} ${newline}Message: ${message}  ${newline}Result: ${event-properties:result}" 
         fileName="${basedir}/${level}.log" />

使用NLog.Fluent命名空间记录调用:

Logging call, using NLog.Fluent namespace:

logger.Info().Message("The service started successfully.")
             .Property("result", The service is listening for requests.")
             .Write(); 

这篇关于如何使用垂直字段而不是水平列进行记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆