使用n日志记录地图VB.Net [英] nlog Logging Map using VB.Net

查看:201
本文介绍了使用n日志记录地图VB.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的 n日志我在 C#的项目,它的工作是魅力,但现在我需要在来使用它VB.NET 的项目,当我转换code我不断收到此错误:

I used nlog in my C# project and it's working as charm, but now I need to use it in VB.NET project and when I convert the code I keep getting this Error:

Overload resolution failed because no accessible 'Info' accepts this number of arguments.  
Overload resolution failed because no accessible 'Debug' accepts this number of arguments.  
Overload resolution failed because no accessible 'Error' accepts this number of arguments.  
Overload resolution failed because no accessible 'Fatal' accepts this number of arguments.  
Overload resolution failed because no accessible 'Warn' accepts this number of arguments.  

这是我的 C# code:

This is my C# Code :

private static readonly Logger ClassLogger = LogManager.GetCurrentClassLogger();
private static readonly Lazy<Dictionary<TraceLevel, Action<string>>> LoggingMap = new Lazy<Dictionary<TraceLevel, Action<string>>>(() => new Dictionary<TraceLevel, Action<string>> { { TraceLevel.Info, ClassLogger.Info }, { TraceLevel.Debug, ClassLogger.Debug }, { TraceLevel.Error, ClassLogger.Error }, { TraceLevel.Fatal, ClassLogger.Fatal }, { TraceLevel.Warn, ClassLogger.Warn } });

private Dictionary<TraceLevel, Action<string>> Logger
    {
        get { return LoggingMap.Value; }
    }

这是 VB.NET 版本:

and this is VB.NET version:

Private Shared ReadOnly ClassLogger As Logger = LogManager.GetCurrentClassLogger()
Private Shared ReadOnly LoggingMap As New Lazy(Of Dictionary(Of TraceLevel, Action(Of String))) _
    (Function() New Dictionary(Of TraceLevel, Action(Of String)) From _
                {{TraceLevel.Info, ClassLogger.Info}, _
                {TraceLevel.Debug, ClassLogger.Debug}, _
                {TraceLevel.Error, ClassLogger.Error}, _
                {TraceLevel.Fatal, ClassLogger.Fatal}, _
                {TraceLevel.Warn, ClassLogger.Warn} _
            })
 Private ReadOnly Property Logger() As Dictionary(Of TraceLevel, Action(Of String))
        Get
            Return LoggingMap.Value
        End Get
    End Property

注意这个错误上升 ClassLogger.Info ...
任何一个可以帮助我找到办法,我收到此错误。
先谢谢你。

Note this Errors rise in ClassLogger.Info ... Can any one help me to find way I'm getting this error. thank you in advance.

推荐答案

在VB.NET,你需要使用的 AddressOf 运营商创建一个函数的委托 - 的 行动(中T) 只是predefined代表 - 这样的code应该是这样的:

In VB.NET, you need to use the AddressOf operator to create a function delegate - Action(Of T) is just a predefined delegate - so the code should look like:

Private Shared ReadOnly LoggingMap As New Lazy(Of Dictionary(Of TraceLevel, Action(Of String))) _
    (Function() New Dictionary(Of TraceLevel, Action(Of String)) From _
                {{TraceLevel.Info, AddressOf ClassLogger.Info}, _
                {TraceLevel.Debug, AddressOf ClassLogger.Debug}, _
                {TraceLevel.Error, AddressOf ClassLogger.Error}, _
                {TraceLevel.Fatal, AddressOf ClassLogger.Fatal}, _
                {TraceLevel.Warn, AddressOf ClassLogger.Warn} _
            })

这篇关于使用n日志记录地图VB.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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