简体   繁体   English

如何将formatProvider参数添加到NLog.LogEventInfo.Create方法?

[英]How to add formatProvider parameter to NLog.LogEventInfo.Create method?

I have following NLog 2.0 code to log exceptions: 我有以下NLog 2.0代码来记录异常:

Dim theEvent = NLog.LogEventInfo.Create(NLog.LogLevel.Error, loggerName, message, ex)

After upgrading to NLog 4.1 I see following warning: 升级到NLog 4.1之后,我看到以下警告:

Function Create(logLevel As LogLevel, loggerName As String, message As String, exception As Exception) As LogEventInfo' is obsolete: 'use Create(LogLevel logLevel, string loggerName, Exception exception, IFormatProvider formatProvider , string message)' 函数Create(logLevel作为LogLevel,loggerName作为字符串,消息作为String,异常作为Exception)作为LogEventInfo'已过时:'使用Create(LogLevel logLevel,字符串loggerName,异常, IFormatProvider formatProvider ,字符串消息)'

... it asks me to add IFormatProvider formatProvider as parameter. ...它要求我添加IFormatProvider formatProvider作为参数。 What should I add there? 我应该在那里添加什么?

Dim theEvent = NLog.LogEventInfo.Create(NLog.LogLevel.Error, loggerName, ex, ???, message)

You can safely use null , one from the System.Globalization.CultureInfo members (a good guide can be found here ) or create your own custom format provider depending on your needs. 您可以安全地使用System.Globalization.CultureInfo成员中的null (可以在此处找到很好的指南),也可以根据需要创建自己的自定义格式提供程序。

The current implementation (as of v.4.1.2 on GitHub ) will simply use CultureInfo.CurrentCulture if the FormatProvider property is null . 如果FormatProvider属性为null则当前实现(从GitHub上 v.4.1.2开始)将仅使用CultureInfo.CurrentCulture

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM