Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should LoggerSource be used in DNN 7+?

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!

like image 809
RacerNerd Avatar asked Oct 04 '13 19:10

RacerNerd


People also ask

What is the best optimizer for DNN?

Now, we have reviewed most of the optimizers for DNN with an intuitive perspective. Some practitioners consider the optimizers like Adam, SGD with momentum, etc. are the SGD with learning rate scheduler.

What is the goal of the optimization of DNN?

The goal of the optimization of DNN is to find the best parameters w to minimize the loss function f (w, x, y), using f (w) bellow for simplification, subject to x, y, where x are the data and y are the labels. The gradient descent ( GD) is the most frequently used optimization method for machine learning.

Which version of DNN Platform should I upgrade to?

If your current version of DNN Platform is between any of the versions listed below, first upgrade to the closest listed version. For instance, if you are starting with version 09.02.00, you should upgrade first to version 09.03.02.

What are the DotNetNuke upgrade notes?

Upgrade Notes: DotNetNuke has been around since 2002, and in that time has had a number of changes which can complicate matters during the process of upgrading through different versions. These include: The changeover from DNN 3.x to DNN 4.x - DNN 3.x used ASP.NET 1.1, whereas DNN 4.x and above require ASP.NET 2.0.


1 Answers

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!

like image 65
RacerNerd Avatar answered Sep 25 '22 17:09

RacerNerd