예제 #1
0
파일: Logger.cs 프로젝트: Yortw/ScribeSharp
        private void WriteEventWithExplicitSource(string eventName, LogEventSeverity eventSeverity, LogEventType eventType, string source, string sourceMethod, int sourceLineNumber, KeyValuePair <string, object>[] properties, Exception exception)
        {
            try
            {
                if (!IsEnabled || !(_FirstChanceFilter?.ShouldLog(eventName, eventSeverity, eventType, source, sourceMethod) ?? true))
                {
                    return;
                }

                using (var pooledLogEvent = _EntryPool.Take())
                {
                    var logEvent = pooledLogEvent.Value;
                    InitialiseLogEvent(eventName, eventSeverity, eventType, properties, exception, logEvent);

                    UnsafeWriteEvent(logEvent, source, sourceMethod, sourceLineNumber);
                }
            }
            catch (LogException lex)
            {
                if (_ErrorHandler.ReportError(lex) == LoggingErrorPolicy.Rethrow)
                {
                    throw;
                }
            }
            catch (Exception ex) when(!ex.ShouldRethrowImmediately())
            {
                var wrappedException = new LogException(ex.Message, ex);

                if (_ErrorHandler.ReportError(wrappedException) == LoggingErrorPolicy.Rethrow)
                {
                    throw wrappedException;
                }
            }
        }
예제 #2
0
파일: Logger.cs 프로젝트: Yortw/ScribeSharp
        /// <summary>
        /// Writes a <see cref="LogEvent"/> to the appropriate output locations if it meets the configured filter.
        /// </summary>
        /// <param name="logEvent">The <see cref="LogEvent"/> instance containing data to write.</param>
        public void WriteEvent(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            try
            {
                if (!IsEnabled || !(_FirstChanceFilter?.ShouldLog(logEvent.EventName, logEvent.EventSeverity, logEvent.EventType, logEvent.Source, logEvent.SourceMethod) ?? true))
                {
                    return;
                }

                UnsafeWriteEvent(logEvent, null, null, -1);
            }
            catch (LogException lex)
            {
                if (_ErrorHandler.ReportError(lex) == LoggingErrorPolicy.Rethrow)
                {
                    throw;
                }
            }
            catch (Exception ex) when(!ex.ShouldRethrowImmediately())
            {
                var wrappedException = new LogException(ex.Message, ex);

                if (_ErrorHandler.ReportError(wrappedException) == LoggingErrorPolicy.Rethrow)
                {
                    throw wrappedException;
                }
            }
        }
예제 #3
0
파일: Logger.cs 프로젝트: Yortw/ScribeSharp
        public void WriteEventWithSource(LogEvent logEvent,
#if SUPPORTS_CALLERATTRIBUTES
                                         [System.Runtime.CompilerServices.CallerFilePath]
#endif
                                         string source = null,
#if SUPPORTS_CALLERATTRIBUTES
                                         [System.Runtime.CompilerServices.CallerMemberName]
#endif
                                         string sourceMethod = null,
#if SUPPORTS_CALLERATTRIBUTES
                                         [System.Runtime.CompilerServices.CallerLineNumber]
#endif
                                         int sourceLineNumber = -1,
                                         bool cloneEvent      = false)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            try
            {
                if (!IsEnabled || !(_FirstChanceFilter?.ShouldLog(logEvent.EventName, logEvent.EventSeverity, logEvent.EventType, logEvent.Source, logEvent.SourceMethod) ?? true))
                {
                    return;
                }

                LogEvent eventToWrite = logEvent;
                PooledObject <LogEvent> pooledLogEvent = null;
                try
                {
                    if (cloneEvent)
                    {
                        pooledLogEvent = _EntryPool.Take();
                        logEvent.Clone(pooledLogEvent.Value);
                        eventToWrite = pooledLogEvent.Value;
                    }

                    if (eventToWrite.DateTime == DateTimeOffset.MinValue)
                    {
                        eventToWrite.DateTime = _LogClock.Now;
                    }

                    UnsafeWriteEvent(eventToWrite, source, sourceMethod, sourceLineNumber);
                }
                finally
                {
                    if (cloneEvent && pooledLogEvent != null)
                    {
                        pooledLogEvent.Dispose();
                    }
                }
            }
            catch (LogException lex)
            {
                if (_ErrorHandler.ReportError(lex) == LoggingErrorPolicy.Rethrow)
                {
                    throw;
                }
            }
            catch (Exception ex) when(!ex.ShouldRethrowImmediately())
            {
                var wrappedException = new LogException(ex.Message, ex);

                if (_ErrorHandler.ReportError(wrappedException) == LoggingErrorPolicy.Rethrow)
                {
                    throw wrappedException;
                }
            }
        }