コード例 #1
0
        private void EnsureLogTypeExists()
        {
            if (DoesLogTypeExist(LOGTYPEKEY))
            {
                return;
            }

            var logTypeInfo = new LogTypeInfo
            {
                LogTypeKey          = LOGTYPEKEY,
                LogTypeFriendlyName = "CloudFlare: Purge Cache",
                LogTypeDescription  = string.Empty,
                LogTypeCSSClass     = "GeneralAdminOperation",
                LogTypeOwner        = "Upendo.Logging.PurgeCloudFlareCacheLogType"
            };

            LogController.Instance.AddLogType(logTypeInfo);

            // Add LogType
            var logTypeConf = new LogTypeConfigInfo
            {
                LoggingIsActive               = true,
                LogTypeKey                    = LOGTYPEKEY,
                KeepMostRecent                = "50",
                NotificationThreshold         = 1,
                NotificationThresholdTime     = 1,
                NotificationThresholdTimeType = LogTypeConfigInfo.NotificationThresholdTimeTypes.Seconds,
                MailFromAddress               = Null.NullString,
                MailToAddress                 = Null.NullString,
                LogTypePortalID               = "*"
            };

            LogController.Instance.AddLogTypeConfigInfo(logTypeConf);
        }
コード例 #2
0
        private ProcessFileResult ProcessStream(Stream stream, LogTypeInfo logTypeInfo, LogFileInfo logFileInfo, IList <IPlugin> plugins)
        {
            var linesProcessed = 0;
            var reader         = logTypeInfo.LogReaderProvider(stream, logFileInfo.FilePath);

            try
            {
                foreach (var line in reader.ReadLines())
                {
                    if (!line.HasContent)
                    {
                        continue;
                    }

                    var logLine = new LogLine(line, logFileInfo);

                    foreach (var plugin in plugins)
                    {
                        plugin.ProcessLogLine(logLine, logTypeInfo.LogType);
                    }

                    ++linesProcessed;
                }
            }
            catch (OutOfMemoryException ex)
            {
                var errorMessage = FailureReasonMessageGenerator.OutOfMemoryError(logFileInfo, plugins);
                _logger.LogInformation(ex, errorMessage);
                return(new ProcessFileResult(linesProcessed, errorMessage, ExitReason.OutOfMemory));
            }

            return(new ProcessFileResult(linesProcessed));
        }
コード例 #3
0
        private ProcessLogTypeResult ProcessZip(LogSetInfo logSetInfo, LogTypeInfo logTypeInfo, IList <IPlugin> plugins)
        {
            var processingStatistics = new ProcessLogTypeResult();

            using var zip = ZipFile.Open(logSetInfo.Path, ZipArchiveMode.Read);
            foreach (var fileEntry in zip.Entries)
            {
                if (!logTypeInfo.FileBelongsToThisType(fileEntry.FullName))
                {
                    continue;
                }

                var fileNameWithPrefix = string.IsNullOrWhiteSpace(logSetInfo.Prefix)
                    ? fileEntry.FullName
                    : $"{logSetInfo.Prefix}/{fileEntry.FullName}";

                _logger.LogInformation("Processing file {logFile}", fileNameWithPrefix);
                var fileTimer         = Stopwatch.StartNew();
                var processFileResult = ProcessZippedFile(fileEntry, fileNameWithPrefix, logTypeInfo, plugins);
                processingStatistics.AddProcessingInfo(fileTimer.Elapsed, fileEntry.Length, processFileResult);

                if (!processFileResult.IsSuccessful)
                {
                    break;
                }

                LogFileProcessingResults(fileNameWithPrefix, fileEntry.Length, processFileResult, fileTimer.Elapsed);
            }

            return(processingStatistics);
        }
コード例 #4
0
        private ProcessLogTypeResult ProcessDir(LogSetInfo logSetInfo, LogTypeInfo logTypeInfo, IList <IPlugin> plugins)
        {
            var processingStatistics = new ProcessLogTypeResult();

            foreach (var filePath in Directory.EnumerateFiles(logSetInfo.Path, "*", SearchOption.AllDirectories))
            {
                var normalizedPath = filePath.NormalizePath(logSetInfo.Path);
                if (!logTypeInfo.FileBelongsToThisType(normalizedPath))
                {
                    continue;
                }

                _logger.LogInformation("Processing file {}", normalizedPath);
                var fileSizeBytes     = new FileInfo(filePath).Length;
                var fileTimer         = Stopwatch.StartNew();
                var processFileResult = ProcessFile(filePath, normalizedPath, logTypeInfo, plugins);
                processingStatistics.AddProcessingInfo(fileTimer.Elapsed, fileSizeBytes, processFileResult);

                if (!processFileResult.IsSuccessful)
                {
                    break;
                }

                LogFileProcessingResults(normalizedPath, fileSizeBytes, processFileResult, fileTimer.Elapsed);
            }

            return(processingStatistics);
        }
コード例 #5
0
 //Log调用
 public static void Print(LogTypeInfo typeInfo, string content)
 {
     //总开关控制  &&   分类开关
     if (bLogRecord && typeInfo.bLogEnable)
     {
         logOut(typeInfo, content);
     }
 }
コード例 #6
0
        public LogTypeInfo GetMyLogType(string logTypeKey)
        {
            LogTypeInfo logType;
            this.LogTypeDictionary.TryGetValue(logTypeKey, out logType);

            if (logType == null)
            {
                logType = new LogTypeInfo();
            }
            return logType;
        }
コード例 #7
0
    private static void logOut(LogTypeInfo typeInfo, string content)
    {
        StringBuilder sb = new StringBuilder();

        sb.Append("[");
        sb.Append(typeInfo.title, typeInfo.titleColor);
        sb.Append("]");
        sb.Append(content, typeInfo.contentColor);

        Debug.Log(sb.ToString());
    }
コード例 #8
0
        public void TestSingleLocationInfo(string filename, bool expectedResult)
        {
            var singleLocationInfo = new LogTypeInfo(LogType.Apache, (stream, _) => new SimpleLinePerLineReader(stream), new List <Regex>
            {
                new Regex(@"fileOne\.txt", RegexOptions.Compiled)
            });

            var result = singleLocationInfo.FileBelongsToThisType(filename);

            result.Should().Be(expectedResult);
        }
コード例 #9
0
        public void TestMultiLocationInfo(string filename, bool expectedResult)
        {
            var singleLocationInfo = new LogTypeInfo(LogType.Apache, _testFunc, new List <Regex>
            {
                new Regex(@"fileOne\.txt", RegexOptions.Compiled),
                new Regex(@"fileTwo\.txt", RegexOptions.Compiled)
            });

            var result = singleLocationInfo.FileBelongsToThisType(filename);

            result.Should().Be(expectedResult);
        }
コード例 #10
0
ファイル: LogDBService.cs プロジェクト: radtek/crm
 /// <summary>
 /// 插入日志类型
 /// </summary>
 public bool InsertLogType(LogTypeInfo info)
 {
     if (info.CreateTime == null)
     {
         info.CreateTime = Utils.GetNow();
     }
     if (info.ModifyTime == null)
     {
         info.ModifyTime = Utils.GetNow();
     }
     SqlMapper.Instance().Insert("LogInfo.InsertLogType", info);
     return(true);
 }
コード例 #11
0
        protected LogTypeInfo GetMyLogType(string logTypeKey)
        {
            LogTypeInfo logType;

            _logTypeDictionary.TryGetValue(logTypeKey, out logType);

// ReSharper disable ConvertIfStatementToNullCoalescingExpression
            if (logType == null)
// ReSharper restore ConvertIfStatementToNullCoalescingExpression
            {
                logType = new LogTypeInfo();
            }
            return(logType);
        }
コード例 #12
0
        protected void Page_Init(Object sender, EventArgs e)
        {
            LogController l = new LogController();

            arrLogTypeInfo = l.GetLogTypeInfo();

            htLogTypeInfo = new Hashtable();

            int i;

            for (i = 0; i <= arrLogTypeInfo.Count - 1; i++)
            {
                LogTypeInfo objLogTypeInfo = (LogTypeInfo)arrLogTypeInfo[i];
                htLogTypeInfo.Add(objLogTypeInfo.LogTypeKey, objLogTypeInfo);
            }

            string ColorCoding;

            ColorCoding = Convert.ToString(Personalization.GetProfile("LogViewer", "ColorCoding"));
            if (ColorCoding == "0")
            {
                ColorCodingOn = false;
            }
            else if (ColorCoding == "1")
            {
                ColorCodingOn = true;
            }
            else
            {
                ColorCodingOn = true;
            }

            string ColorCodingLegend;

            ColorCodingLegend = Convert.ToString(Personalization.GetProfile("LogViewer", "ColorCodingLegend"));
            if (ColorCodingLegend == "0")
            {
                ColorCodingLegendOn = false;
            }
            else if (ColorCodingLegend == "1")
            {
                ColorCodingLegendOn = true;
            }
            else
            {
                ColorCodingLegendOn = true;
            }
        }
コード例 #13
0
        private static void RegisterLogType(string logTypeKey, string logTypeFriendlyName, string cssClass,
                                            LogController controller)
        {
            if (controller.GetLogTypeInfoDictionary().ContainsKey(logTypeKey))
            {
                //Add LogType
                var logTypeInfo = controller.GetLogTypeInfoDictionary()[logTypeKey];
                logTypeInfo.LogTypeFriendlyName = logTypeFriendlyName;
                logTypeInfo.LogTypeDescription  = string.Empty;
                logTypeInfo.LogTypeCSSClass     = cssClass;
                logTypeInfo.LogTypeOwner        = "Hotcakes.Logging.EventLogType";
                controller.UpdateLogType(logTypeInfo);
            }
            else
            {
                //Add LogType
                var logTypeInfo = new LogTypeInfo
                {
                    LogTypeKey          = logTypeKey,
                    LogTypeFriendlyName = logTypeFriendlyName,
                    LogTypeDescription  = string.Empty,
                    LogTypeCSSClass     = cssClass,
                    LogTypeOwner        = "Hotcakes.Logging.EventLogType"
                };
                controller.AddLogType(logTypeInfo);

                //Add LogType
                var logTypeConf = new LogTypeConfigInfo
                {
                    LoggingIsActive               = true,
                    LogTypeKey                    = logTypeKey,
                    KeepMostRecent                = "100",
                    NotificationThreshold         = 1,
                    NotificationThresholdTime     = 1,
                    NotificationThresholdTimeType = LogTypeConfigInfo.NotificationThresholdTimeTypes.Seconds,
                    MailFromAddress               = Null.NullString,
                    MailToAddress                 = Null.NullString,
                    LogTypePortalID               = "*"
                };

                controller.AddLogTypeConfigInfo(logTypeConf);
            }
        }
コード例 #14
0
ファイル: LogDBService.cs プロジェクト: radtek/crm
 /// <summary>
 /// 更新日志类型
 /// </summary>
 public bool UpdateLogType(LogTypeInfo info)
 {
     SqlMapper.Instance().Update("LogInfo.UpdateLogType", info);
     return(true);
 }
コード例 #15
0
        private ProcessFileResult ProcessFile(string rawFilePath, string normalizedFilePath, LogTypeInfo logTypeInfo, IList <IPlugin> plugins)
        {
            var fileInfo    = new FileInfo(rawFilePath);
            var logFileInfo = new LogFileInfo(
                fileInfo.Name,
                normalizedFilePath,
                normalizedFilePath.GetWorkerIdFromFilePath(),
                new DateTimeOffset(fileInfo.LastWriteTime.Ticks, TimeSpan.Zero).UtcDateTime
                );

            using var stream = File.Open(rawFilePath, FileMode.Open);
            return(ProcessStream(stream, logTypeInfo, logFileInfo, plugins));
        }
コード例 #16
0
 public virtual void UpdateLogType(LogTypeInfo objLogTypeInfo)
 {
     LoggingProvider.Instance().UpdateLogType(objLogTypeInfo.LogTypeKey, objLogTypeInfo.LogTypeFriendlyName, objLogTypeInfo.LogTypeDescription, objLogTypeInfo.LogTypeCSSClass, objLogTypeInfo.LogTypeOwner);
 }
コード例 #17
0
 public LogTypeModel(LogTypeInfo logtype)
 {
     LogType = logtype.LogTypeFriendlyName;
     Enabled = true;
     Notify  = false;
 }
コード例 #18
0
        private ProcessLogTypeResult ProcessLogType(IEnumerable <LogSetInfo> logSetParts, LogTypeInfo logTypeInfo, IList <IPlugin> plugins)
        {
            var overallProcessingNumbers = new ProcessLogTypeResult();

            using var _ = _logger.BeginScope(logTypeInfo.LogType);

            foreach (var logSetInfo in logSetParts)
            {
                _logger.LogInformation("Starting to process log set part `{logSetPartPath}` for {logType} logs", logSetInfo.Path, logTypeInfo.LogType);
                var partProcessingResults = logSetInfo.IsZip
                    ? ProcessZip(logSetInfo, logTypeInfo, plugins)
                    : ProcessDir(logSetInfo, logTypeInfo, plugins);
                _logger.LogInformation("Completed processing `{logSetPartPath}` for {logType} logs. {partProcessingResults}", logSetInfo.Path, logTypeInfo.LogType, partProcessingResults);
                overallProcessingNumbers.AddNumbersFrom(partProcessingResults);

                if (!partProcessingResults.IsSuccessful)
                {
                    break;
                }
            }

            return(overallProcessingNumbers);
        }
コード例 #19
0
        private ProcessFileResult ProcessZippedFile(ZipArchiveEntry fileEntry, string filePathWithPrefix, LogTypeInfo logTypeInfo, IList <IPlugin> plugins)
        {
            var logFileInfo = new LogFileInfo(
                fileEntry.Name,
                filePathWithPrefix,
                filePathWithPrefix.GetWorkerIdFromFilePath(),
                new DateTimeOffset(fileEntry.LastWriteTime.Ticks, TimeSpan.Zero).UtcDateTime // the ZipArchiveEntry doesn't currently support reading the timezone of the zip entry... so we strip it for consistency
                );

            // currently because of how zips store (or don't) timezone info for entries, the zipped and unzipped versions of this method produce different output.  Perhaps we can do better in the future.

            using var stream = fileEntry.Open();
            return(ProcessStream(stream, logTypeInfo, logFileInfo, plugins));
        }
コード例 #20
0
 public virtual void DeleteLogType(LogTypeInfo objLogTypeInfo)
 {
     LoggingProvider.Instance().DeleteLogType(objLogTypeInfo.LogTypeKey);
 }