예제 #1
0
        public bool MoveNext()
        {
            GuardState();
            var result = Log4JParserC.Log4JIteratorMoveNext(impl_);

            return(result);
        }
예제 #2
0
        private Log4JFile(UnmanagedMemoryHandle buffer, long size)
        {
            buffer_ = buffer;
            Size    = size;
            var status = Log4JParserC.Log4JEventSourceInitXmlString(out impl_, buffer_.DangerousGetHandle());

            switch (status)
            {
            case Log4JParserC.Status.Success:
                break;

            case Log4JParserC.Status.DocumentErrors:
                break;

            case Log4JParserC.Status.MemoryError:
                impl_.Dispose();
                throw new OutOfMemoryException();

            default:
                impl_.Dispose();
                throw new InvalidOperationException();
            }

            Encoding = Encoding.ASCII;
        }
예제 #3
0
        internal override HandleGraph <FilterHandle> Build(Encoding encoding)
        {
            HandleGraph <FilterHandle> child = null;
            FilterHandle primaryFilter       = null;

            // There can be a maximum of 3 exceptions if filter initialization fails:
            // * Initial exception that caused the initialization to fail.
            // * Exception raised when calling primaryFilter.Dispose ().
            // * Exception raised when calling child.Dispose ().
            var cleanupErrors = new List <Exception> (3);

            try
            {
                child = Child.Build(encoding);

                Log4JParserC.Log4JFilterInitNot(out primaryFilter, child.Handle);

                return(HandleGraph.Composite(primaryFilter, child));
            }
            catch (Exception initEx)
            {
                cleanupErrors.Add(initEx);
                Disposable.TryDispose(primaryFilter, cleanupErrors);
                Disposable.TryDispose(child, cleanupErrors);

                if (cleanupErrors.Count > 1)
                {
                    throw new AggregateException(cleanupErrors);
                }

                throw;
            }
        }
예제 #4
0
        public IList <KeyValuePair <string, string> > GetProperties()
        {
            const int bufferSize = 16;
            var       buffer     = new Log4JEventProperty[bufferSize];

            var result = new List <KeyValuePair <string, string> > (16);

            uint totalEvents;
            var  totalEventsRead = 0U;

            do
            {
                totalEvents = Log4JParserC
                              .Log4JEventProperties(impl_, new UIntPtr(totalEventsRead), buffer, new UIntPtr((uint)buffer.Length))
                              .ToUInt32();

                var eventsRemaining = totalEvents - totalEventsRead;
                var eventsRead      = eventsRemaining > bufferSize ? bufferSize : eventsRemaining;

                for (var i = 0U; i < eventsRead; ++i)
                {
                    var name  = PtrToString(buffer[i].Name, buffer[i].NameSize);
                    var value = PtrToString(buffer[i].Value, buffer[i].ValueSize);
                    result.Add(new KeyValuePair <string, string> (name, value));
                }

                totalEventsRead += eventsRead;
            } while (totalEventsRead != totalEvents);

            return(result);
        }
예제 #5
0
            private static IteratorHandle Init(IteratorHandle inner, HandleGraph <FilterHandle> filterHandle)
            {
                IteratorHandle result;

                Log4JParserC.Log4JIteratorInitFilter(out result, inner, filterHandle.Handle);

                return(result);
            }
예제 #6
0
                private static IteratorHandle Init(EventSourceHandle source)
                {
                    IteratorHandle result;

                    Log4JParserC.Log4JIteratorInitEventSourceReverse(out result, source);

                    return(result);
                }
예제 #7
0
        internal override HandleGraph <FilterHandle> Build(Encoding encoding)
        {
            FilterHandle result = null;

            try
            {
                Log4JParserC.Log4JFilterInitTimestamp(out result, Min, Max);
                return(HandleGraph.Simple(result));
            }
            catch (Exception ex)
            {
                Disposable.DisposeAggregateErrors(result, ex);
                throw;
            }
        }
예제 #8
0
            public int Compare(string x, string y)
            {
                var xVal = Log4JParserC.Log4JGetLevelValueNt(x);

                if (xVal < 0 && xVal != Int32.MinValue)
                {
                    throw new ArgumentException("Unrecognized log level.", nameof(x));
                }

                var yVal = Log4JParserC.Log4JGetLevelValueNt(y);

                if (yVal < 0 && yVal != Int32.MinValue)
                {
                    throw new ArgumentException("Unrecognized log level.", nameof(y));
                }

                return(Comparer <int> .Default.Compare(xVal, yVal));
            }
예제 #9
0
        internal override HandleGraph <FilterHandle> Build(Encoding encoding)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            var logger     = encoding.GetBytes(Logger);
            var loggerSize = new UIntPtr((uint)logger.Length);

            FilterHandle result = null;

            try
            {
                Log4JParserC.Log4JFilterInitLoggerFs(out result, logger, loggerSize);
                return(HandleGraph.Simple(result));
            }
            catch (Exception ex)
            {
                Disposable.DisposeAggregateErrors(result, ex);
                throw;
            }
        }
예제 #10
0
 /// <inheritdoc />
 protected override bool ReleaseHandle()
 {
     Log4JParserC.Log4JEventSourceDestroy(handle);
     return(true);
 }
예제 #11
0
 /// <inheritdoc />
 protected override bool ReleaseHandle()
 {
     Log4JParserC.Log4JIteratorDestroy(handle);
     return(true);
 }