当前位置: 首页>>代码示例>>C#>>正文


C# LogLevels.ToString方法代码示例

本文整理汇总了C#中LogLevels.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LogLevels.ToString方法的具体用法?C# LogLevels.ToString怎么用?C# LogLevels.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogLevels的用法示例。


在下文中一共展示了LogLevels.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteLog

        private static void WriteLog(LogLevels level, string message)
        {
            if (!Directory.Exists(LogFolder))
            {
                Directory.CreateDirectory(LogFolder);
            }

            if (level >= Settings.settingsStore.logLevel)
            {
                string output;
                if (Settings.settingsStore.useUTCTimeInLog)
                {
                    output = "[" + DateTime.UtcNow.ToString("HH:mm:ss") + "][" + level.ToString() + "] : " + message;
                }
                else
                {
                    output = "[" + DateTime.Now.ToString("HH:mm:ss") + "][" + level.ToString() + "] : " + message;
                }
                Console.WriteLine(output);
                ClientHandler.SendConsoleMessageToAdmins(output);
                try
                {
                    lock (logLock) {
                        File.AppendAllText(LogFilename, output + Environment.NewLine);
                    }
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Error writing to log file!, Exception: " + e);
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
            }
        }
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:34,代码来源:Log.cs

示例2: LogData

 private void LogData(string message, LogLevels level, Exception exception)
 {
     if (LogLevel <= level)
     {
         if (exception == null)
         {
             LogData(string.Format("{0} - {1} - {2} - {3}", DateTime.Now.ToString("MM/dd/yyyy HH:nn:ss.fffff"), ClassLogger.ToString(), level.ToString(), message));
         }
         else
         {
             LogData(string.Format("{0} - {1} - {2} - {3}::\r\n{4}", DateTime.Now.ToString("MM/dd/yyyy HH:nn:ss.fffff"), ClassLogger.ToString(), level.ToString(), message, exception.ToString()));
         }
     }
 }
开发者ID:russjudge,项目名称:ArtemisSBS-ProtocolSharp,代码行数:14,代码来源:Log.cs

示例3: AltLog

 /// <summary>
 /// Logs a message to the database logger.
 /// If logger not defined, logs to the console.
 /// </summary>
 public static void AltLog(LogLevels eventType, int id, string message, bool forceconsole = false)
 {
     if (!forceconsole && Logger != null)
         Logger.TraceEvent(eventType, id, message);
     else
         Console.WriteLine(eventType.ToString() + " " + id + " " + LMLoggers.LognLM.FlattenChars(message));
 }
开发者ID:tempbottle,项目名称:INCC6,代码行数:11,代码来源:DB.cs

示例4: Format

 public static string Format(DateTime dateTime,LogLevels level,string toWrite)
 {
     var levelString = level.ToString().Substring(3).ToUpper();
     return string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00} ({6}) {7}",
                                              dateTime.Year,
                                              dateTime.Month,
                                              dateTime.Day,
                                              dateTime.Hour,
                                              dateTime.Minute,
                                              dateTime.Second,
                                              levelString,
                                              toWrite
         );
 }
开发者ID:kendarorg,项目名称:ZakFramework,代码行数:14,代码来源:LoggerFormatter.cs

示例5: WriteLog

        private static void WriteLog(LogLevels level, string format, params object[] args)
        {
            if (level < MinLogLevel) { return; }

            lock (Console.Out)
            {
                string Line = string.Format("[{0}] [{1}] : {2}", DateTime.Now.ToString("HH:mm:ss"), level.ToString(), string.Format(format, args));
                Console.WriteLine(Line);
                try
                {
                    File.AppendAllText(LogFilename, Line + Environment.NewLine);
                }
                catch { } //What do we do about this?
            }
        }
开发者ID:Wingman-mn,项目名称:KerbalMultiPlayer,代码行数:15,代码来源:Logger.cs

示例6: WriteLog

        private static void WriteLog(LogLevels level, string message)
        {
            if (!Directory.Exists(logDir))
            {
                Directory.CreateDirectory(logDir);
            }

            string output = "[" + DateTime.Now.ToString("HH:mm:ss") + "][" + level.ToString() + "] : " + message;
            Console.WriteLine(output);
            
            try
            {
                File.AppendAllText(logFile, output + Environment.NewLine);
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Error writing to log file!, Exception: " + e);
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
开发者ID:RockyTV,项目名称:AutoUpdater,代码行数:21,代码来源:Log.cs

示例7: WriteLog

        private static void WriteLog(LogLevels level, string format, params object[] args)
        {
            if (level < MinLogLevel) { return; }

            string output = string.Format("[{0}] : {1}", level.ToString(), string.Format(format, args));

            switch (level)
            {
                case LogLevels.Debug:
                case LogLevels.Activity:
                case LogLevels.Info:
                case LogLevels.Notice:
                    UnityEngine.Debug.Log(output);
                    break;
                case LogLevels.Warning:
                    UnityEngine.Debug.LogWarning(output);
                    break;
                case LogLevels.Error:
                    UnityEngine.Debug.LogError(output);
                    break;
            }
        }
开发者ID:RockyTV,项目名称:KerbalMultiPlayer,代码行数:22,代码来源:Logger.cs

示例8: SetSessionLogLevel

 public void SetSessionLogLevel(LogLevels level)
 {
     ExecuteApplication("session_loglevel", level.ToString().ToLower(), true);
 }
开发者ID:weijunbao,项目名称:freeswitch-socket-dotnet,代码行数:4,代码来源:InboundConnection.cs

示例9: Log

 public void Log(LogLevels level, string message)
 {
     ExecuteApplication("log", level.ToString().ToUpper() + " " + message, false);
 }
开发者ID:weijunbao,项目名称:freeswitch-socket-dotnet,代码行数:4,代码来源:InboundConnection.cs

示例10: logToFile

        private static void logToFile(string message, LogLevels level, DateTime dateTime, string exceptionMessage, string stack, int sourceId, int exceptionId)
        {
            try
            {
                var dateString = dateTime.ToString("yyyy/MM/dd hh:mm:sstt");
                var indentStr = new string(' ', dateString.Length + 2); // +2 to accommodate log type and spaces

                if (!string.IsNullOrEmpty(message))
                {
                    message = message.Replace("\r\n", "\r").Replace("\n", "\r").Replace("\r", " | ");
                }

                if (!string.IsNullOrEmpty(exceptionMessage))
                {
                    exceptionMessage = exceptionMessage.Replace("\r\n", "\r").Replace("\n", "\r").Replace("\r", " | ");
                }

                var levelSymbol = level.ToString()[0];

                var logText = "";

                switch (level)
                {
                    case LogLevels.Debug:
                    case LogLevels.Info:
                        // basic non-error logging
                        logText = string.Format(
                             "{0} {1} {2} (Source {3})\r\n",
                             dateString,
                             levelSymbol,
                             message,
                             sourceId);
                        break;

                    case LogLevels.Warning:
                    case LogLevels.Error:
                    case LogLevels.FatalError:
                        // get that stack trace indented!
                        string indentedStack = "";
                        if (stack != null)
                        {
                            indentedStack = stack.Replace("\r\n", "\r\n" + indentStr);
                            indentedStack = indentStr + indentedStack.Substring(0, indentedStack.Length - indentStr.Length);
                        }

                        // log exception details
                        logText = string.Format(
                             "{0} {1} {2} (SourceID {3})\r\n{4} {5} (ExceptionID {6})\r\n{7}\r\n\r\n",
                             dateString,
                             levelSymbol,
                             message,
                             sourceId,
                             indentStr,
                             exceptionMessage,
                             exceptionId,

                             indentedStack);
                        break;
                }

                //log to the correct stream if configured, otherwise log to default location (not efficient as the file is opened each time)
                if (_logFileStream != null)
                {
                    _logFileStream.Write(logText);
                    if ((_logFileMaxSize > 0) && (_logFileStream.BaseStream.Length > _logFileMaxSize))
                    {
                        truncateFile();
                    }
                }
                else
                {
                    lock (_fileLock)
                    {
                        //2012/03/15 - params were the wrong way round!
                        File.AppendAllText(DefaultLogFileName, logText);
                    }
                }
            }
            catch
            {

            }
        }
开发者ID:Flowgear,项目名称:flowgear-logging,代码行数:83,代码来源:Logging.cs

示例11: WriteLog

        private static void WriteLog(LogLevels level, string format, params object[] args)
        {
            if (level < MinLogLevel)
            {
                return;
            }

            string output = string.Format("[{0}] : {1}", level.ToString(), string.Format(format, args));

            switch (level)
            {
                case LogLevels.Debug:
                case LogLevels.Activity:
                case LogLevels.Info:
                case LogLevels.Notice:
                    if (useDelayedLogging)
                    {
                        delayedDebugQueue.Enqueue(output);
                    }
                    else
                    {
                        UnityEngine.Debug.Log(output);
                    }
                    break;
                case LogLevels.Warning:
                    if (useDelayedLogging)
                    {
                        delayedWarningQueue.Enqueue(output);
                    }
                    else
                    {
                        UnityEngine.Debug.LogWarning(output);
                    }
                    break;
                case LogLevels.Error:
                    if (useDelayedLogging)
                    {
                        delayedErrorQueue.Enqueue(output);
                    }
                    else
                    {
                        UnityEngine.Debug.LogError(output);
                    }
                    break;
            }
        }
开发者ID:TehGimp,项目名称:KerbalMultiPlayer,代码行数:46,代码来源:Logger.cs

示例12: Log

        private async void Log(DateTime dateTimeStamp, LogLevels level, Type logInitiator, string loggedFrom, string message)
        {
            //Always verify the log level before adding a log entry.
            if (level >= _logLevel)
            {
                string methodName;

                switch (level)
                {
                    case LogLevels.All:
                        methodName = "Log";
                        break;
                    case LogLevels.Info:
                        methodName = "LogInfo";
                        break;
                    case LogLevels.Warn:
                        methodName = "LogWarn";
                        break;
                    case LogLevels.Error:
                        methodName = "LogError";
                        break;
                    case LogLevels.Fatal:
                        methodName = "LogFatal";
                        break;
                    default:
                        methodName = "LogDebug";
                        break;
                }

                StringParameters dsp = null;
                if (level == LogLevels.All)
                {
                    dsp = new StringParameters();
                    dsp.Add(new StringParameter(PARAM_NAME_LEVEL, level.ToString()));
                }

                logBase log = new logBase(dateTimeStamp, logInitiator.FullName, loggedFrom, message);

                FacadeResponse<string> fr;

                fr = await JsonFacade.SendRequest<string>(string.Format("{0}{1}", _baseAddress, methodName),
                                                          log, HTTPVerbs.POST, dsp);
            }
        }
开发者ID:bwship,项目名称:athena-toolkit,代码行数:44,代码来源:LogProviderJson.cs

示例13: SendToAdmin

 private static void SendToAdmin(LogLevels level, string format, params object[] args)
 {
     try {
         string Line = string.Format("[{0}] : {1}", level.ToString (), string.Format(format, args));
         ServerMain.server.sendTextMessageToAdmins(Line);
     }
     catch (Exception) {};
 }
开发者ID:Josvth,项目名称:KerbalMultiPlayer,代码行数:8,代码来源:Logger.cs

示例14: WriteLog

        /// <summary>
        /// Overload to write a message and exception to the logging system
        /// </summary>
        /// <param name="LoggerType">Type of logger to use</param>
        /// <param name="LogLevel">Level of log reporting</param>
        /// <param name="InpMsg">Message to be logged</param>
        /// <param name="Ex">Exception to be logged</param>
        public static void WriteLog(LoggerTypes LoggerType, LogLevels LogLevel, string InpMsg, Exception Ex)
        {
            ILog MyLogger;

            //Establish which logger will be used
            switch (LoggerType)
            {
                case LoggerTypes.LogDb:
                    MyLogger = m_DbLogger;
                    break;
                case LoggerTypes.LogFile:
                    MyLogger = m_FileLogger;
                    // Check to determine if a new file should be started
                    var TestFileDate = DateTime.Now.ToString("MM-dd-yyyy");
                    if (TestFileDate != m_FileDate)
                    {
                        m_FileDate = TestFileDate;
                        ChangeLogFileName();
                    }
                    break;
                case LoggerTypes.LogSystem:
                    MyLogger = m_SysLogger;
                    break;
                default:
                    throw new Exception("Invalid logger type specified");
            }

            //Update the status file data
            clsStatusData.MostRecentLogMessage = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "; "
                    + InpMsg + "; " + LogLevel.ToString();

            //Send the log message
            switch (LogLevel)
            {
                case LogLevels.DEBUG:
                    if (MyLogger.IsDebugEnabled)
                        MyLogger.Debug(InpMsg, Ex);
                    break;
                case LogLevels.ERROR:
                    clsStatusData.AddErrorMessage(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "; " + InpMsg
                         + "; " + LogLevel.ToString());

                    if (MyLogger.IsErrorEnabled)
                        MyLogger.Error(InpMsg, Ex);
                    break;
                case LogLevels.FATAL:
                    if (MyLogger.IsFatalEnabled)
                        MyLogger.Fatal(InpMsg, Ex);
                    break;
                case LogLevels.INFO:
                    if (MyLogger.IsInfoEnabled)
                        MyLogger.Info(InpMsg, Ex);
                    break;
                case LogLevels.WARN:
                    if (MyLogger.IsWarnEnabled)
                        MyLogger.Warn(InpMsg, Ex);
                    break;
                default:
                    throw new Exception("Invalid log level specified");
            }
        }
开发者ID:PNNL-Comp-Mass-Spec,项目名称:DMS-Space-Manager,代码行数:68,代码来源:clsLogTools.cs

示例15: WriteLog

        private static void WriteLog(LogLevels level, string format, params object[] args)
        {
            if (!Directory.Exists(LogFolder))
                Directory.CreateDirectory(LogFolder);

            if (level < MinLogLevel) { return; }

            lock (Console.Out)
            {
                string Line = string.Format("[{0}] [{1}] : {2}", DateTime.Now.ToString("HH:mm:ss"), level.ToString(), string.Format(format, args));
                Console.WriteLine(Line);
                try
                {
                    File.AppendAllText(LogFilename, Line + Environment.NewLine);
                }
                catch { } //What do we do about this?
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
开发者ID:RcColes,项目名称:KerbalMultiPlayer,代码行数:19,代码来源:Logger.cs


注:本文中的LogLevels.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。