Log4net, how to log a verbose message?

前端 未结 6 860
醉酒成梦
醉酒成梦 2020-12-14 09:53

I can log info messages without a problem, but can\'t figure out how to log verbose messages. Any help would be welcomed.

My problem is:

loggingEvent.Level

6条回答
  •  猫巷女王i
    2020-12-14 10:35

    In case off someone still need the answer (without using System.Reflection) It's not necessary to set DeclaringType, just set null (auto resolve in Lo4Net)

    public bool IsVerboseEnable { get { return _log.Logger.IsEnabledFor(Level.Verbose); } }
    
    public string Verbose(string text)
    {
        _log.Logger.Log(null, Level.Verbose, text, null);
        return text;
    }
    

    Tested & Validated

    Code use in log4net

    public virtual void Log(Type callerStackBoundaryDeclaringType, Level level, object message, Exception exception)
    {
        try
        {
            if (this.IsEnabledFor(level))
            {
                this.ForcedLog((callerStackBoundaryDeclaringType != null) ? callerStackBoundaryDeclaringType : Logger.declaringType, level, message, exception);
            }
        }
        catch (Exception exception2)
        {
            LogLog.Error(Logger.declaringType, "Exception while logging", exception2);
        }
    }
    

提交回复
热议问题