Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Issues with NLog

Issues with NLog

Søren Heide Larsen
Søren Heide Larsen
Reply

Hi Dynamicweb,

After spending hours trying to figure out why NLog suddenly stops working, i realize that it is due to the fact that Dynamicweb overrides the NLog.Configuration and that some complex rules in their targets seems to cause issues with what we log.

Now as we use Glimpse.NLog and our own targets as well, we kinda dislike this type of implementation, so we suggest that you implement this using traditional nlog.config instead of hardcoding a overwrite of the file. If you really want to inject rules by code, I suggest you sees how Glimpse.NLog does it.

 

If other have issues with this as well I made a small notification subscriber, which will let you work with your own logging.

    /// <summary>
    /// NORRIQ currently uses Nlog.config, however, Dynamicweb overwrites everything with their abstraction!
    /// Lets take the power back to the people and restore the original configuration after Dw does their trickeries!
    /// </summary>
    [Subscribe(Dynamicweb.Notifications.Standard.Application.BeforeStart),
     Subscribe(Dynamicweb.Notifications.Standard.Application.AfterStart)]
    public class ForceXmlConfigurationNlogNotificationSubscriber : NotificationSubscriber
    {
        private static LoggingConfiguration _configuration;

        public ForceXmlConfigurationNlogNotificationSubscriber()
        {
            _configuration = _configuration ?? NLog.LogManager.Configuration;
        }
        public override void OnNotify(string notification, NotificationArgs args)
        {
            if (string.Equals(notification, Dynamicweb.Notifications.Standard.Application.AfterStart, StringComparison.CurrentCultureIgnoreCase))
            {
                // This line will overwrite of LogManager.Configuration based on Dynamicwebs implementation :/
                var forceCurrentLogManager = Dynamicweb.Logging.LogManager.Current;

                // We will set it back!
                NLog.LogManager.Configuration = _configuration;
            }
        }
    }

Replies

 
Martin Vang
Martin Vang
Reply

Hi Søren,

I assume that NLog does not suddenly stop working? Our code-implemented configuration of logging isn't that new. :)

Anyway, I just wanted to make a quick comment about the above code probably breaking all logging in Dynamicweb. It overrides the following (quick overview to highlight most important parts):

Placement of logging files

Condition based filters

Rules (exception/standard/trace)

Tracing configuration

GlobalThreshold

Use with caution!

BR

Martin

 
Søren Heide Larsen
Søren Heide Larsen
Reply

Hi Martin,

I believe the biggest issue was that it suddenly stopped working in the middle of the application lifecycle when the first Dynamicweb logging occoured. And in some of our less e-commerce applications, that may take a while, thus everything seems to work perfectly untill we hit some code that uses Dynamicweb logging. We also use NLog for application health surveillance purposes so NLog is critical for us. I noticed that the global threshold was modified as well and made a change for that .

I would really like you to use Common.logging and NLog as it is intended instead of having to overwrite everything. As it is now I will not be able to both use the "standard" logging you provide and our own logging/glimpse without having to hack the application. You could achieve this in several different ways:

  • Inject the code as you do now but in a less hostile manner: see. https://github.com/rho24/Glimpse.NLog/blob/master/Glimpse.NLog/NLogInspector.cs 
  • Writing your targets/rules in a configuration file and include it through Web.config (e.g. <nlog><include file="${basedir}Files/System/DynamicwebNLog.config" /></nlog>. This also makes the rules editable for your partners.

/Søren

 
Martin Vang
Martin Vang
Reply

Hi Søren,

I'm not going to defend a "hardcoded" configuration. I just wanted to make it clear, what happens when it is overridden. :)

The choice to hardcode the configuration is was to make it difficult to change the configuration. I know... But that was the decission at the time.

I'll take your complaint and discuss it with our product owner. It will be seen as a feature request, and will be discussed some time after 9.3 has been released (TFS 36356).

BR

Martin

 
Søren Heide Larsen
Søren Heide Larsen
Reply

Hi Martin,

I know the world is not perfect, I just wanted to share the frustration i got when facing something like this :)

But as we now have a workaround we can use as a temporarily best-practise internally, I am happy for now and thank you for the quick reaction.

/Søren

 

 
Hans Kloppenborg
Reply

Hi Søren,

Thanks for finding the reason Nlog is behaving weird. We noticed the same sort of problems but assumed that our hosting in Azure was the reason, not that DW just overwrote the config.

Is there a work around to keep our own logging working that you know of? Can we disable DW logging totally?

Greets Hans

 
Søren Heide Larsen
Søren Heide Larsen
Reply
This post has been marked as an answer

Hi Hans,

There are no way to disable this behavour, though the workaround I posted initially simply forces Dynamicweb to do their trickeries and overwrites what they do afterwards, thus allowing you to control NLog - We now use this on all our Dynamicweb 9 solutions.

Note that you may want to overwrite default log level as well as Dynamicweb also overwrites this.

/Søren

Votes for this answer: 1

 

You must be logged in to post in the forum