Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging 如何使用垂直字段而不是水平列进行日志记录?_Logging_Nlog - Fatal编程技术网

Logging 如何使用垂直字段而不是水平列进行日志记录?

Logging 如何使用垂直字段而不是水平列进行日志记录?,logging,nlog,Logging,Nlog,我正在使用NLog.EventLog目标,并使用API以垂直字段格式记录事件 它可能看起来像这样: Method: ServiceBase.Manager.StartService() Message: The service started successfully. Result: The service is listening for requests. 这可能吗?当然可以,类似这样: Method: ServiceBase.Manager.StartService() Mess

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

它可能看起来像这样:

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

这可能吗?

当然可以,类似这样:

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

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

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

根据朱利安的回答,我得出以下结论:

--配置方法--

--助手类--


这是新行的布局。

太棒了!关键在于
NewLine
layout。我想对日志调用的详细性进行一点详细说明,所以我只是在初始配置中使用了布局。请参阅我的代码备选答案。不过,了解
事件属性
布局还是不错的。我会好好利用它的。以及流畅的语法。谢谢
Public Class Layouts
  Public Sub New(Layouts As List(Of String))
    Me.Layouts = Layouts
  End Sub

  Shared Sub New()
    _CallSite = "${callsite}"
    _Message = "${message}"
    _NewLine = "${newline}"
  End Sub

  Public Overrides Function ToString() As String
    Return Join(Me.Layouts.ToArray, "|")
  End Function

  Private Layouts As List(Of String)

  ''' <summary>
  ''' The call site (class name, method name and source information).
  ''' </summary>
  Public Shared ReadOnly Property CallSite As String

  ''' <summary>
  ''' The formatted log message.
  ''' </summary>
  Public Shared ReadOnly Property Message As String

  ''' <summary>
  ''' A newline literal.
  ''' </summary>
  Public Shared ReadOnly Property NewLine As String
End Class
Method:     ServiceBase.Manager.StartService()
Level:      Info
Message:    Service started