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


C# LogLevels.Equals方法代码示例

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


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

示例1: Log

        public static void Log(string logname, LogLevels level, string codeLocation, string logevent, string notes)
        {
            if (level >= _logLevel)
            {
                #region DETERMINE LOG FILE NAME
                string filename;
                if (_isLoggingByHour) filename = String.Format("{0}_{1}_{2}_{3}_{4}{5}", logname, DateTime.Now.Year, DateTime.Now.Month.ToString("00"), DateTime.Now.Day.ToString("00"), DateTime.Now.Hour.ToString("00"), _extension);
                else if (_isLoggingByDay) filename = String.Format("{0}_{1}_{2}_{3}{4}", logname, DateTime.Now.Year, DateTime.Now.Month.ToString("00"), DateTime.Now.Day.ToString("00"), _extension);
                else filename = logname + _extension;
                #endregion

                bool isError = level.Equals(LogLevels.ERROR);

                #region Prepare entry - remove newlines, commas, add date
                codeLocation = codeLocation.Replace(NEWLINE, ";").Replace(",", ";");
                logevent = logevent.Replace(NEWLINE, ";").Replace(",", ";");
                notes = notes.Replace(NEWLINE, ";").Replace(",", ";");

                string datetime = String.Format("{0}/{1}/{2} {3}:{4}:{5}", DateTime.Now.Month.ToString("00"), DateTime.Now.Day.ToString("00"), DateTime.Now.Year.ToString("00"), DateTime.Now.Hour.ToString("00"), DateTime.Now.Minute.ToString("00"), DateTime.Now.Second.ToString("00"));
                long tickCount = Environment.TickCount;
                long sinceTick = tickCount - _lastTick;
                _lastTick = tickCount;
                #endregion

                string logDirectory = LogDirectory();
                string filepath = Path.Combine(logDirectory, filename);

                try
                {
                    StringBuilder sbEntry = new StringBuilder();

                    bool isFirstTime = false;
                    if (!_isLoggingToBuffer && (!_pathCurrentLog.Equals(filepath) || (_sw == null))) isFirstTime = OpenLogFile(filepath);

                    #region header information if new file
                    if (isFirstTime && _isIncludingHeader && !_isLoggingToBuffer)
                    {
                        //application name; application version; machine name
                        sbEntry.Append(String.Format("{0} {1} {2} {3}", GetApplicationName(), GetApplicationVersion(), GetMachineName(), NEWLINE));
                        //screen width and height
                        sbEntry.Append(String.Format("screen width {0} x height {1}{2}", System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, NEWLINE));
                        //OS version and name; .NET Framework version; culture language
                        sbEntry.Append(String.Format("{0};{1};.NET Framework {2};{3};{4}", Environment.OSVersion.ToString(), GetOperatingSystem(), Environment.Version.ToString(), CultureInfo.CurrentCulture.EnglishName, NEWLINE));
                        //culture date format; culture time format; local date; universal date
                        sbEntry.Append(String.Format("{0};{1};{2};{3};{4}", CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern, DateTime.Now, DateTime.UtcNow, NEWLINE));
                        sbEntry.Append(NEWLINE);
                        sbEntry.Append(",DateTime,Tick,Elapsed,Level,CodeLocation,LogEvent,Notes");
                        //if (_isIncludingSystemInfo)
                        //    sbEntry.Append(SystemStatus.StatusColumns);
                        sbEntry.Append(NEWLINE);
                    }
                    #endregion

                    #region ASSEMBLE LOG ENTRY
                    sbEntry.Append(String.Format(",{0},{1},{2},{3},{4},{5},{6}", datetime, tickCount, sinceTick, LevelLabel(level), codeLocation, logevent, notes));
                    //if (_isIncludingSystemInfo) sbEntry.Append(SystemStatus.GetStatusString());
                    #endregion

                    #region WRITE LOG ENTRY
                    lock (typeof(Logger))
                    {
                        string logEntry = sbEntry.ToString();
                        if (!_isLoggingToBuffer)
                        {
                            WriteToFile(logEntry, isError);
                        }
                        else
                        {
                            WriteToBuffer(logEntry);
                            if (isError && _writesBufferToFileOnError) WriteBufferToFile();
                        }

                        if (_isLoggingToConsole) Console.WriteLine(logEntry);
                    }
                    #endregion

                }
                catch {}

                #region IF LIMITING SIZE AND LOG EXCEEDS SIZE, RENAME
                if (!_isLoggingToBuffer && _isLimitingSize)
                {
                    FileInfo fi = new FileInfo(filepath);
                    if ((fi.Length / 1000) > _kbSizeLimit)
                    {
                        CloseLogFile();
                        string fileCopy = String.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}{7}", logname, DateTime.Now.Year, DateTime.Now.Month.ToString("00"), DateTime.Now.Day.ToString("00"), DateTime.Now.Hour.ToString("00"), DateTime.Now.Minute.ToString("00"), DateTime.Now.Second.ToString("00"), _extension);
                        try
                        {
                            File.Copy(filepath, Path.Combine(logDirectory, fileCopy), true);
                            File.Delete(filepath);
                        }
                        catch { }
                    }
                }
                #endregion

                #region DELETE OLD FILES
                if (_deletesOldLogs)
                {
//.........这里部分代码省略.........
开发者ID:katadam,项目名称:wockets,代码行数:101,代码来源:Logger.cs


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