Ejemplo n.º 1
0
 public void Test1()
 {
     LogDescriptor desc = new LogDescriptor();
     var now = DateTime.Now;
     var str = desc.Describe(Log.Logger, new LogItem()
     {
         Time = now,
         Message = "测试内容。",
         Type = LogType.Info
     });
     Assert.Equal(now.ToString("HH:mm:ss.ffff") + " [消息] 测试内容。", str);
 }
Ejemplo n.º 2
0
        public void Test1()
        {
            LogDescriptor desc = new LogDescriptor();
            var           now  = DateTime.Now;
            var           str  = desc.Describe(Log.Logger, new LogItem()
            {
                Time    = now,
                Message = "测试内容。",
                Type    = LogType.Info
            });

            Assert.Equal(now.ToString("HH:mm:ss.ffff") + " [消息] 测试内容。", str);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 从描述符创建日志。
        /// </summary>
        /// <param name="descriptor">给定的 <see cref="LogDescriptor"/>。</param>
        /// <returns>返回 <see cref="Log"/>。</returns>
        public static Log CreateFromDescriptor(LogDescriptor descriptor)
        {
            descriptor.NotNull(nameof(descriptor));

            return(new Log
            {
                UserId = descriptor.UserId,
                AssocId = descriptor.AssocId,
                Name = descriptor.Name,
                Descr = descriptor.Descr,
                CreatedTime = DateTime.Now
            });
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Function responsible for writing to the debug log.
    /// </summary>
    /// <param name="debugLevel"> Debug level of this message, from enum EDebugLevel.</param>
    /// <param name="incomingMessage"> The message to write.</param>
    public void WriteToLog(EDebugLevel debugLevel, object incomingMessage)
    {
#if DEBUG_LEVEL_WARN
        if ((debugLevel & EDebugLevel.DEBUG_WARN) != 0)
        {
            Debug.Log(WARN_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(WARN_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_WARN

#if DEBUG_LEVEL_ERROR
        if ((debugLevel & EDebugLevel.DEBUG_ERROR) != 0)
        {
            Debug.Log(ERROR_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(ERROR_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_ERROR

#if DEBUG_LEVEL_CRITICAL
        if ((debugLevel & EDebugLevel.DEBUG_CRITICAL) != 0)
        {
            Debug.Log(CRITICAL_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(CRITICAL_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_CRITICAL

#if DEBUG_LEVEL_INFO
        if ((debugLevel & EDebugLevel.DEBUG_INFO) != 0)
        {
            Debug.Log(INFO_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(INFO_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_INFO
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Function responsible for writing to the debug log.
    /// </summary>
    /// <param name="debugLevel"> Debug level of this message, from enum EDebugLevel.</param>
    /// <param name="incomingMessage"> The message to write.</param>
    public void WriteToLog(EDebugLevel debugLevel, object incomingMessage)
    {
#if DEBUG_LEVEL_WARN
        if ((debugLevel & EDebugLevel.DEBUG_WARN) != 0)
        {
            Debug.Log(WARN_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(WARN_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_WARN

#if DEBUG_LEVEL_ERROR
        if ((debugLevel & EDebugLevel.DEBUG_ERROR) != 0)
        {
            Debug.Log(ERROR_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(ERROR_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_ERROR

#if DEBUG_LEVEL_CRITICAL
        if ((debugLevel & EDebugLevel.DEBUG_CRITICAL) != 0)
        {
            Debug.Log(CRITICAL_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(CRITICAL_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_CRITICAL

#if DEBUG_LEVEL_INFO
        if ((debugLevel & EDebugLevel.DEBUG_INFO) != 0)
        {
            Debug.Log(INFO_MESSAGE + incomingMessage);
            LogDescriptor newException = new LogDescriptor(INFO_MESSAGE + incomingMessage);
            if (m_currentLogs != null)
            {
                m_currentLogs.Add(newException);
            }
        }
#endif //DEBUG_LEVEL_INFO
    }