<commit_before>﻿using System;
using System.Web;
using log4net;
using log4net.Config;
using Sdl.Web.Common.Interfaces;

namespace Sdl.Web.Common.Logging
{
    public class Log4NetLogger : ILogger
    {
        private static readonly ILog _log = LogManager.GetLogger(typeof(Log4NetLogger));

        private const string TraceFormat = "url:{0},type:{1},time:{2},details:{3}";

        #region ILogger members

        public void Trace(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (IsTracingEnabled)
            {
                // no trace output available in log4net so we use debug instead but we should move to
                // using the same logging as the CIL library (trace listeners) and then we can remove 
                // the log4net dependency from DXA and instead provide a DXA logging module that will 
                // allow people to use it if they wish by implementing a trace listener to forward on
                // log writes to log4net.
                log.DebugFormat(messageFormat, parameters);   
            }
        }

        public void Debug(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsDebugEnabled)
            {
                log.DebugFormat(messageFormat, parameters);
            }
        }

        public void Info(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsInfoEnabled)
            {
                log.InfoFormat(messageFormat, parameters);
            }
        }

        public void Warn(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsWarnEnabled)
            {
                log.WarnFormat(messageFormat, parameters);
            }
        }

        public void Error(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsErrorEnabled)
            {
                log.ErrorFormat(messageFormat, parameters);
            }
        }

        public void Error(Exception ex, string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsErrorEnabled)
            {
                log.Error(String.Format(messageFormat,parameters),ex);
            }
        }

        public void Error(Exception ex)
        {
            ILog log = _log;            
            if (log.IsErrorEnabled)
            {
                log.Error(ex.Message, ex);
            }
        }

        public static void Configure()
        {
            XmlConfigurator.Configure();
        }

        public bool IsTracingEnabled
        {
            get
            {
                return _log.IsDebugEnabled;
            }
        }
        #endregion
    }
}
<commit_msg>added proper trace output using log4net<commit_after>﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.Web;
using log4net;
using log4net.Config;
using log4net.Util;
using Sdl.Web.Common.Interfaces;

namespace Sdl.Web.Common.Logging
{
    public class Log4NetLogger : ILogger
    {
        private static readonly ILog _log = LogManager.GetLogger(typeof(Log4NetLogger));

        private const string TraceFormat = "url:{0},type:{1},time:{2},details:{3}";

        #region ILogger members

        public void Trace(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (IsTracingEnabled)
            {          
                // the log4net wrapper doesn't actually have a Trace method so instead we implement our own. we are lucky because log4net DOES include
                // a trace level in its enum :-)
                System.Reflection.MethodBase mb = new StackFrame(3).GetMethod();
                log.Logger.Log(mb.DeclaringType, log4net.Core.Level.Trace, new SystemStringFormat(CultureInfo.InvariantCulture, messageFormat, parameters), null);
            }
        }

        public void Debug(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsDebugEnabled)
            {
                log.DebugFormat(messageFormat, parameters);
            }
        }

        public void Info(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsInfoEnabled)
            {
                log.InfoFormat(messageFormat, parameters);
            }
        }

        public void Warn(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsWarnEnabled)
            {
                log.WarnFormat(messageFormat, parameters);
            }
        }

        public void Error(string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsErrorEnabled)
            {
                log.ErrorFormat(messageFormat, parameters);
            }
        }

        public void Error(Exception ex, string messageFormat, params object[] parameters)
        {
            ILog log = _log;
            if (log.IsErrorEnabled)
            {
                log.Error(String.Format(messageFormat,parameters),ex);
            }
        }

        public void Error(Exception ex)
        {
            ILog log = _log;            
            if (log.IsErrorEnabled)
            {
                log.Error(ex.Message, ex);
            }
        }

        public static void Configure()
        {
            XmlConfigurator.Configure();
        }

        public bool IsTracingEnabled
        {
            get
            {
                return _log.Logger.IsEnabledFor(log4net.Core.Level.Trace);
            }
        }
        #endregion
    }
}

{'fraction_non_alphanumeric': 0.07783505154639175, 'fraction_numerical': 0.004467353951890034, 'mean_word_length': 1.5144708423326134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3855034', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1445, 'n_words': 389}