예제 #1
0
        public void Log(Type source, Core.LogLevel level, Exception exception, string message, params object[] args)
        {
            ILogger logger = getLogger(this.GetType());

            var logEvent = getLogEvent(source, level, exception, message, args);

            logger.Log(logEvent);
        }
예제 #2
0
        public BepInEx.Logging.LogLevel Convert(Core.LogLevel level)
        {
            switch (level)
            {
            case Core.LogLevel.Debug:
                return(BepInEx.Logging.LogLevel.Debug);

            case Core.LogLevel.Info:
                return(BepInEx.Logging.LogLevel.Info);

            case Core.LogLevel.Warn:
                return(BepInEx.Logging.LogLevel.Warning);

            case Core.LogLevel.Error:
                return(BepInEx.Logging.LogLevel.Error);

            default:
                return(BepInEx.Logging.LogLevel.None);
            }
        }
예제 #3
0
        private LogEventInfo getLogEvent(Type source, Core.LogLevel level, Exception exception, string format, object[] args)
        {
            string assemblyProp     = string.Empty;
            string classProp        = string.Empty;
            string methodProp       = string.Empty;
            string messageProp      = string.Empty;
            string innerMessageProp = string.Empty;

            var logEvent = new LogEventInfo(NLog.LogLevel.FromOrdinal((int)level), source.FullName, string.Format(format, args));

            logEvent.Exception = exception;

            if (exception != null)
            {
                assemblyProp = exception.Source;
                classProp    = exception.TargetSite.DeclaringType.FullName;
                methodProp   = exception.TargetSite.Name;
                messageProp  = exception.Message;

                if (exception.InnerException != null)
                {
                    innerMessageProp = exception.InnerException.Message;
                }
            }
            else
            {
                assemblyProp = source.FullName;
                classProp    = source.Name;
            }

            logEvent.Properties["LOGGER"]     = assemblyProp;
            logEvent.Properties["CLASS"]      = classProp;
            logEvent.Properties["METHOD"]     = methodProp;
            logEvent.Properties["EXCEPTION"]  = messageProp;
            logEvent.Properties["STACKTRACE"] = innerMessageProp;

            return(logEvent);
        }
예제 #4
0
 protected override void Log(Core.LogLevel level, string message)
 {
     _logger.Log(Convert(level), message);
 }