How to use LoggerSource in DNN 7+?

I am implementing registration on my DNN 7+ website. I would like to have a custom logging level, e.g. with log4net.

I tried to follow the log4net integration instructions found on the DNN website, http://www.dnnsoftware.com/community-blog/cid/141723/Using-log4net-with-DotNetNuke . After adding the link and line of code to use the log:

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

A warning is reported in the code that states:

'DotNetNuke.Instrumentation.DnnLog' deprecated: '' Depreciated at 7.0.1 due to poor performance, use LoggerSource.Instance "''

I find it difficult to find information on the right way to do something. It seems that "DnnLog" has been replaced by a similar class for interacting with log4net called "DnnLogger". One difference from using this class (and the "LoggerSource" class) is that logging is no longer performed using static methods.

The GetLogger () function used to retrieve the log instance accepts some parameters, and I have not yet been able to find the documentation describing the corresponding use. The DNN source has many examples. From these examples, it can be seen that the corresponding use is for delivering the current class. Inside the file "MyClass.cs", which declares the class "MyClass", it looks like this:

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

or

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

Which logger is returned by the first line of code using typeof ()? By this I mean, will this logger use the log4net settings configured for the site? If it does not use log4net parameters, where are the log files stored and where are the configuration parameters configured? The nerd in me wants to know exactly what happens to the typeof () class parameter, why is it used?

If the first example doesn't connect to log4net (or something that allows a customizable easy-to-use logging level), is the second option the way to go? If so, which line should go? "MyClass" was my hunch, but I couldn't confirm.

If I am fully tracking here and should approach this from a different direction, feel free to respond to offers.

Thanks everyone!

+5
source share
1 answer

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

  • The depreciated class had performance issues as the log was using static methods. The new style uses non-static methods, so each page or class can create its own registrar instance. This prevents the program from waiting for a shared instance if a simultaneous log request is made.
  • ILog and DNNLogger use the log4net configuration.
  • Using ILog with LoggerSource brings you closer to the roots, so it's better to use than DNNLogger, but there is not much difference.
  • The best way to get a logging object:

     ILog logger = LoggerSource.Instance.GetLogger(typeof(MyClass)); 
  • Passing a class name helps contextualize error information when reading a log file. When a class is used, the log file will contain the namespace and class along with error information.

  • To use the LoggerSource and ILog classes, the following statement is required:

     using DotNetNuke.Instrumentation; 

I hope this information helps anyone who is wondering about making changes to DNN 7.
Happy coding!

+7
source

All Articles