Frage

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.

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' is obsolete: '"Depreciated in 7.0.1 due to poor performance, use LoggerSource.Instance"'

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.

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));

or

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

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?

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.

Thanks a lot everyone!

War es hilfreich?

Lösung

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

  • 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.

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

    using DotNetNuke.Instrumentation;
    

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top