Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DotLess Custom Logger configured from the web.config

I have created a custom logger by implementing the dotless.Core.Loggers.ILogger interface.

Now I try to use this logger by configuring it in out web.config like this:

<dotless minifyCss="false" cache="false" web="false" logger="company.product.server.dotLess.CLessLogger" log="debug" />

Problem is: no trace is written and my custom logger is never called / created.

If I change the logger to one of the standard loggers like the ResponseLogger:

<dotless minifyCss="false" cache="false" web="false" logger="dotless.Core.Loggers.AspResponseLogger" log="debug" />

I get a logging message in the response as expected.

The code for the custom logger simply forwards the logging to our own tracer:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using company.product.server.tools.trace;
using dotless.Core.Loggers;
using log4net.Core;

namespace company.product.server.dotLess
{
    public class CLessLogger : dotless.Core.Loggers.ILogger
    {
        public CLessLogger()
        {
            CTracerFactory tracerFactory = new CTracerFactory();
            m_tracer = tracerFactory.GetTracer(this.GetType().ToString());
        }
        public void Log(LogLevel level, string message)
        {   
            switch(level) {
                case LogLevel.Debug:
                    Debug(message);
                    break;
                case LogLevel.Error:
                    Error(message);
                    break;
                case LogLevel.Info:
                    Info(message);
                    break;
                case LogLevel.Warn:
                    Warn(message);
                    break;
            }
        }

        public void Info(string message)
        {
            m_tracer.Info(message);
        }

        public void Debug(string message)
        {
            m_tracer.Debug(message);
        }

        public void Warn(string message)
        {
            m_tracer.Warning(message);
        }

        public void Error(string message)
        {
            m_tracer.Error(message);
        }

        ITracer m_tracer;


        #region ILogger Members

        public void Debug(string message, params object[] args)
        {
            m_tracer.DebugFormat(message, args);
        }

        public void Error(string message, params object[] args)
        {
            m_tracer.ErrorFormat(message, args);
        }

        public void Info(string message, params object[] args)
        {
            m_tracer.InfoFormat(message, args);
        }

        public void Warn(string message, params object[] args)
        {
            m_tracer.InfoFormat(message, args);
        }

        #endregion
    }
}

What am I doing wrong?

(I already posted this in the DotLess google group, but after not getting any reply for two days I decided to crosspost this, hope that's okay)

like image 953
stefan.s Avatar asked Nov 01 '22 07:11

stefan.s


1 Answers

The logger entry in the config element needs the fully qualified name for the class, including the assembly. So, for this:

logger="company.product.server.dotLess.CLessLogger"

if the assembly is named company.product, you actually need to put this in place:

logger="company.product.server.dotLess.CLessLogger, company.product"

Add , company.product to the end, and it should work.

like image 101
Charles Boyung Avatar answered Nov 16 '22 11:11

Charles Boyung