예제 #1
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;
 }
예제 #2
0
 public static void Init(DiagnosticsConfig config)
 {
     if (config == null)
     {
         return;
     }
     if (config.EventFilters != null)
     {
         foreach (FilterConfig filterConfig in config.EventFilters)
         {
             var filter = ConstructObject(filterConfig.TypeName) as IEventFilter;
             if (filter != null)
             {
                 filter.Init(filterConfig.Props);
                 EventFilters.Add(filter);
             }
         }
     }
     if (config.Writers == null)
     {
         return;
     }
     GroupByField        = config.GroupBy.Trim();
     GroupByFieldDefined = !string.IsNullOrEmpty(GroupByField);
     foreach (WriterConfig writer in config.Writers)
     {
         var eventWriterTriplet = new EventWriterTriplet
         {
             Writer = ConstructObject(writer.TypeName) as IEventWriter
         };
         if (eventWriterTriplet.Writer == null)
         {
             continue;
         }
         eventWriterTriplet.Writer.Init(writer.Props);
         eventWriterTriplet.Formatter = ConstructObject(writer.EventFormatter.TypeName) as IEventFormatter;
         if (eventWriterTriplet.Formatter == null)
         {
             eventWriterTriplet.Formatter = new Default.EventFormatter();
         }
         else
         {
             eventWriterTriplet.Raw = writer.EventFormatter.Raw;
         }
         eventWriterTriplet.Formatter.Init(writer.EventFormatter.Props);
         foreach (FilterConfig filterConfig in writer.EventFilters)
         {
             var filter = ConstructObject(filterConfig.TypeName) as IEventWriterFilter;
             if (filter != null)
             {
                 filter.Init(filterConfig.Props);
                 eventWriterTriplet.Filters.Add(filter);
             }
         }
         s_eventWriterTriplets.Add(eventWriterTriplet);
     }
 }
예제 #3
0
 public bool Accepted(EventWriterTriplet writerTriplet, LoggerEvent loggerEvent, string message)
 {
     var newMessage = loggerEvent.Properties[LoggerEvent.MESSAGE_PROPERTY].ToString();
     bool asseptResult = false;
     if (!loggerEvent.Properties.ContainsKey(BpcLoggerExtensions.MESSAGEID_PROPERTY))
         asseptResult = true;
     else if (!_filteredTypes.Contains((Message)loggerEvent.Properties[BpcLoggerExtensions.MESSAGEID_PROPERTY]))
         asseptResult = true;
     else if (writerTriplet.Raw)
     {
         newMessage = string.Format(newMessage, (object[])loggerEvent[LoggerEvent.PARAMETERS_PROPERTY]);
         asseptResult = _lastMessageText != newMessage;
     }
     else if (!writerTriplet.Raw && _lastMessageText != newMessage)
         asseptResult = true;
     _lastMessageText = newMessage;
     return asseptResult;
 }
예제 #4
0
 public static void Init(DiagnosticsConfig config)
 {
     if (config == null)
         return;
     if (config.EventFilters != null)
     {
         foreach (FilterConfig filterConfig in config.EventFilters)
         {
             var filter = ConstructObject(filterConfig.TypeName) as IEventFilter;
             if (filter != null)
             {
                 filter.Init(filterConfig.Props);
                 EventFilters.Add(filter);
             }
         }
     }
     if (config.Writers == null)
         return;
     GroupByField = config.GroupBy.Trim();
     GroupByFieldDefined = !string.IsNullOrEmpty(GroupByField);
     foreach (WriterConfig writer in config.Writers)
     {
         var eventWriterTriplet = new EventWriterTriplet
                                      {
                                          Writer = ConstructObject(writer.TypeName) as IEventWriter
                                      };
         if (eventWriterTriplet.Writer == null)
             continue;
         eventWriterTriplet.Writer.Init(writer.Props);
         eventWriterTriplet.Formatter = ConstructObject(writer.EventFormatter.TypeName) as IEventFormatter;
         if (eventWriterTriplet.Formatter == null)
         {
             eventWriterTriplet.Formatter = new Default.EventFormatter();
         }
         else
         {
             eventWriterTriplet.Raw = writer.EventFormatter.Raw;
         }
         eventWriterTriplet.Formatter.Init(writer.EventFormatter.Props);
         foreach (FilterConfig filterConfig in writer.EventFilters)
         {
             var filter = ConstructObject(filterConfig.TypeName) as IEventWriterFilter;
             if (filter != null)
             {
                 filter.Init(filterConfig.Props);
                 eventWriterTriplet.Filters.Add(filter);
             }
         }
         s_eventWriterTriplets.Add(eventWriterTriplet);
     }
 }