We start with log4net in DNN

Contents

We start with the first DunkedNetNuke post talking about one of the added features of the version 6 de DNN, log4net. This tool will be familiar to you because it is a port of the excellent tool Marco Apache log4j ™ to the Microsoft environment, taking advantage of all the new features .GRANDCHILD, to offer us a solid system for generating and sending logs to multiple destinations.

implementl_log4net_net-2047622

To configure this functionality we only have to access the DotNetNuke.log4net.config file in which we can see the output of all the logs that we want to create. By default, generating logs of all error logs in the web application targeting Portales / _default / Logs. For this reason, if our registration system is going to be different, it would be interesting not to store these registers by deactivating this appender by default by changing the value of the level to “OFF”.

We can see how each output of the logs is generated by an appender, in which the configurations of the same are defined to finally use it in a logger. You can create as many appenders and loggers as different outputs you want to generate.

Now we are going to add a new appender to our logger to output a udp broadcast constant showing only application errors:

We create the new appender

We assign it within the root tag or create a logger for it.

As you can see we have defined a different level of log generation “ERROR” since we are only interested in obtaining the errors and not all the information generated by our DNN instance, let's not forget that we are going to send it constantly flowing data through the network. This practice can be very useful for the development phases since it allows us to constantly see all the records of the application that interest us.

To receive the stream and view it we can use any streaming consumer app, in this case we will use log4view with the following settings:

2015-10-14_11-49-45-4510654

If you're using Windows 7 or later and performs tests locally, use the loopback ip ending in 2, things that have IPv6

With this we will have our receiver configured so we will begin to capture the errors sent through the UDP broadcast generated by log4net.

2015-10-14_11-54-51-1911763

Now we will proceed to create the critical error submission via Email for which we will add another appender:

In this way we will achieve that in case a critical error occurs, en unos momentos tendremos una alerta con información importante para su rápida resolution:

2015-10-14_12-16-00-4416506

The previous example has been made for a connection to an SMTP server with basic authentication through the TLS protocol, but if we wanted to send our mail for example from a personal gmail account we would have to use the following configuration to enable SSL and allow gmail to use sources that are not secure for sending by mail.

2015-10-13_11-44-48-1126907

And we enable the use of untrusted sources or our emails will not reach the gmail smtp server

Finally, on many occasions we will have to debug operation from log4net itself, for this we can in turn generate a log of its operation by adding these lines to the web.config file of our application inside :

<add
name = “textWriterTraceListener”
type = “System.Diagnostics.TextWriterTraceListener”
initializeData = “C: myweb.dnndev.me log4net websites.txt” />

In this way you will have a new log in which you can observe the processes carried out by log4view and debug possible errors in a simpler way:

2015-10-14_12-43-47-2693522

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.