在DNN 7+中应如何使用LoggerSource? [英] How should LoggerSource be used in DNN 7+?

查看:82
本文介绍了在DNN 7+中应如何使用LoggerSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究在DNN 7+网站上实现日志记录.我想要一个可配置的日志记录级别,例如与log4net一起提供的日志记录级别.

I have been looking into implementing logging on my DNN 7+ site. I would like to have a configurable logging level such as that provided with log4net.

我试图按照说明集成DNN网站上的log4net,此处 http://www.dnnsoftware.com/community-blog/cid/141723/Using-log4net-with-DotNetNuke .添加引用和代码行以使用日志记录之后:

I attempted to follow the instructions to integrate log4net found on the DNN site here, http://www.dnnsoftware.com/community-blog/cid/141723/Using-log4net-with-DotNetNuke. After adding the reference and the line of code to use the logging:

DnnLog.Info("My Logging Worked!");

该代码报告了一条警告,内容为:

The code reported a warning that reads:

'DotNetNuke.Instrumentation.DnnLog'已过时:' 7.0.1由于性能不佳,请使用LoggerSource.Instance'

'DotNetNuke.Instrumentation.DnnLog' is obsolete: '"Depreciated in 7.0.1 due to poor performance, use LoggerSource.Instance"'

我很难找到有关正确的做事方式的信息.似乎"DnnLog"已被替换为与名为"DnnLogger"的log4net进行交互的类似类.使用此类(和"LoggerSource"类)的区别之一是不再使用静态方法来完成日志记录.

I am having a hard time finding information about the right way to do things. It appears that "DnnLog" has been replaced with a similar class to interact with log4net called "DnnLogger". One of the differences with using this class (and the "LoggerSource" class) is that logging is no longer accomplished using static methods.

用于检索记录器实例的"GetLogger()"函数带有一些参数,但我还找不到任何描述适当用法的文档. DNN来源有很多示例.从这些示例中,看起来合适的用法是提供当前类.在声明了"MyClass"类的文件"MyClass.cs"中,以下内容将是正确的:

The "GetLogger()" function used to retrieve the logger instance takes some parameters and I have not yet been able to find any documentation describing the appropriate usage. The DNN source has plenty of examples. From these examples it looks like the appropriate usage is to supply the current class. Inside a file "MyClass.cs" that declares a class "MyClass" it appears the following would be correct:

ILog logger = LoggerSource.Instance.GetLogger(typeof(MyClass));

DnnLogger logger = DnnLogger.GetLogger("MyClass");

使用typeof()的第一行代码返回什么记录器?我的意思是,此记录器将使用为该站点配置的log4net设置吗?如果未使用log4net设置,则在哪里保存日志文件,并在哪里调整配置设置?我内心的书呆子想确切地知道typeof()类参数正在发生什么,为什么要使用它?

What logger is returned by the first line of code that uses the typeof()? By this I mean, will this logger then be using the log4net settings configured for the site? If it isn't using the log4net settings, where are the log files saved and where are configuration settings adjusted? The nerd in me wants to know exactly what is happening with the typeof() class parameter, why is it used?

如果第一个示例未与log4net连接(或允许可配置的易于使用的日志记录级别的连接),那么第二个选择是否可行?如果是这样,要传递的适当字符串是什么?我的猜测是"MyClass",但我无法确认.

If the first example does not connect with log4net (or something that allows a configurable easy to use logging level), is the second option the way to go? If so, what is the appropriate string to be passing? "MyClass" was my guess but I could not confirm.

如果我在这里完全偏离轨道,并且应该从另一个方向来处理这个问题,请随时提出建议.

If I am totally off track here and should be approaching this from another direction please feel free to chime in with suggestions.

非常感谢大家!

推荐答案

我在

I posted this same question on the DNN Software forums and got a quick answer. To paraphrase and expand on that answer:

  • 折旧的类存在性能问题,因为日志记录是 使用静态方法完成.新样式使用非静态方法,因此 每个页面或类都可以创建自己的记录器实例.这 防止程序在以下情况下等待共享实例 同时发生日志请求.
  • ILog和DNNLogger都使用log4net配置.
  • 将ILog与LoggerSource结合使用会使您更接近根源,因此比DNNLogger更好地使用它,但两者之间并没有太大区别.
  • 获取用于记录的对象的最佳方法是:

  • The depreciated class had performance issues because the logging was done using static methods. The new style uses non-static methods so each page or class can create it's own instance of the logger. This prevents the program from waiting for the shared instance when a simultaneous log request occurs.
  • ILog and DNNLogger both use the log4net configuration.
  • Using ILog with LoggerSource gets you closer to the roots so it's better to use than DNNLogger but there isn't much difference.
  • The best way to get an object for logging is:

ILog logger = LoggerSource.Instance.GetLogger(typeof(MyClass));

  • 传递类名有助于上下文化错误信息 在读取日志文件时.使用该类时,日志文件将 包含名称空间和类以及错误信息.

  • Passing the class name helps contextualize the error information while reading the log file. When the class is used the log file will contain the namespace and class along with the error information.

    要使用LoggerSource和ILog类,需要以下using语句:

    To use the LoggerSource and ILog class the following using statement is needed:

    using DotNetNuke.Instrumentation;
    

  • 希望此信息对任何对DNN 7中的日志记录更改有所疑问的人有所帮助.
    祝您编程愉快!

    Hopefully this info helps anyone who is wondering about the logging changes in DNN 7.
    Happy Coding!

    这篇关于在DNN 7+中应如何使用LoggerSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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