示例#1
0
        private static string ApplyLogEventParams(LoggerEvent logEvent)
        {
            var resultMsg = logEvent.Properties[LoggerEvent.MESSAGE_PROPERTY].ToString();

            if (logEvent.Properties.ContainsKey(LoggerEvent.PARAMETERS_PROPERTY))
            {
                resultMsg = BpcLoggerExtensions.
                            GetMessageBody((Message)logEvent.Properties[BpcLoggerExtensions.MESSAGEID_PROPERTY]);
                resultMsg =
                    String.Format(resultMsg, (object[])logEvent.Properties[LoggerEvent.PARAMETERS_PROPERTY]);
            }
            return(resultMsg);
        }
示例#2
0
        public bool Accepted(EventWriterTriplet writerTriplet, LoggerEvent logEvent, string message)
        {
            if (!(writerTriplet.Writer is IEventFileSystemWriter))
            {
                return(true);
            }
            string uniqueId = EventDispatcher.GetUniqueId(logEvent);

            if (_blockedLogs.Contains(uniqueId))
            {
                return(false);
            }
            var pointName = DEFAULT_LOG_NAME;

            if (EventDispatcher.GroupByFieldDefined && logEvent.Properties.ContainsKey(EventDispatcher.GroupByField))
            {
                var groupByFieldValue = (string)logEvent[EventDispatcher.GroupByField];
                if (_minFreeSpaces.ContainsKey(groupByFieldValue))
                {
                    pointName = groupByFieldValue;
                }
            }
            var  minFreeSpace = _minFreeSpaces[pointName];
            var  requiredSize = message.Length / FileUtils.BYTES_IN_KB + 1;
            long availableSize;
            var  fileSystemManager = GetFileSystemManager();

            if (fileSystemManager != null &&
                !fileSystemManager.ReserveDiskSpace(
                    (writerTriplet.Writer as IEventFileSystemWriter).GetPoint(uniqueId),
                    requiredSize,
                    minFreeSpace,
                    out availableSize))
            {
                var errorEvent = new LoggerEvent {
                    EventType = TraceEventType.Error
                };
                errorEvent[LoggerEvent.LOGGERNAME_PROPERTY]        = logEvent[LoggerEvent.LOGGERNAME_PROPERTY];
                errorEvent[BpcLoggerExtensions.MESSAGEID_PROPERTY] =
                    Message.Common_AvailableSpaceFilterNotEnoughSpaceError;
                var minSizeMb       = (double)minFreeSpace / FileUtils.BYTES_IN_KB;
                var availableSizeMb = (double)availableSize / FileUtils.BYTES_IN_MB;
                if (writerTriplet.Raw)
                {
                    errorEvent[LoggerEvent.MESSAGE_PROPERTY] =
                        Message.Common_AvailableSpaceFilterNotEnoughSpaceError;
                    errorEvent[LoggerEvent.PARAMETERS_PROPERTY] =
                        new object[] { uniqueId, availableSizeMb, minSizeMb };
                }
                else
                {
                    errorEvent[LoggerEvent.MESSAGE_PROPERTY] =
                        string.Format(
                            BpcLoggerExtensions.GetMessageBody(Message.Common_AvailableSpaceFilterNotEnoughSpaceError),
                            uniqueId, availableSizeMb, minSizeMb);
                }
                writerTriplet.Writer.Write(uniqueId, writerTriplet.Formatter.Format(errorEvent));
                if (!_blockedLogs.Contains(uniqueId))
                {
                    _blockedLogs.Add(uniqueId);
                }
                return(false);
            }
            return(true);
        }