예제 #1
0
        private void TraceInternal(TraceCategory traceCategory, int errorCode, TraceEventType traceEventType, string traceEventName, DateTime?traceDate,
                                   TimeSpan?elapsedTime, Exception exception, string message, TraceContext context)
        {
            if (_traceSource == null)
            {
                throw new InvalidOperationException("SetSource() must be called before.");
            }
            // if no date were specified use now
            DateTime creationDate = traceDate ?? HighResolutionDateTime.UtcNow;

            // mapping TraceCategory System.Diagnostics.TraceEventType
            System.Diagnostics.TraceEventType dotnetTraceEventType = CategoryMapper[traceCategory];
            TraceEventData traceEvent =
                new TraceEventData
            {
                CreationDate     = creationDate,
                ContextParameter = context?.ToString(),
                CorrelationId    = GetCorrelationId(),
                SessionId        = GetSessionId(),
                UserName         = GetPrincipalId(),
                ElapsedTime      = elapsedTime,
                ErrorCode        = errorCode,
                RawException     = exception,
                TraceCategory    = traceCategory,
                TraceEventType   = traceEventType,
                TraceEventName   = traceEventName,
                TraceSourceName  = _traceSourceName,
                TraceSourceType  = _traceSourceType,
                Message          = message,
            };

            traceEvent.ComputeAutomaticProperties();
            _traceSource.TraceData(dotnetTraceEventType, errorCode, traceEvent);
        }
예제 #2
0
 /// <summary>
 /// This method provide to set severity of exception.
 /// </summary>
 /// <param name="ex">Exception.</param>
 /// <param name="severity">Severity.</param>
 public static void SetSeverity(Exception ex, System.Diagnostics.TraceEventType severity)
 {
     if (!ex.Data.Contains(Constants.SeverityKey))
     {
         ex.Data.Add(Constants.SeverityKey, severity.ToString());
     }
 }
예제 #3
0
 public void Write(System.Diagnostics.TraceEventType type, string format, params object[] args)
 {
     if (args == null)
     {
         throw new ArgumentNullException("args");
     }
     Source.TraceEvent(type, 0, format, args);
 }
예제 #4
0
        protected override void TraceEvent(int id, System.Diagnostics.TraceEventType messageType, object message, Exception exception)
        {
            base.TraceEvent(id, messageType, message, exception);

            var traceString = GetTraceEventString(id, messageType, message, exception);

            Trace.WriteLine(traceString);
        }
예제 #5
0
        /// <summary>
        ///     Trace the specified data.
        /// </summary>
        /// <param name="eventCache">The specified cache object.</param>
        /// <param name="source">The name of the source</param>
        /// <param name="eventType">The specified System.Dagnostics trace event type.</param>
        /// <param name="id">The specified event id.</param>
        /// <param name="data">The custom data object that will hold our <see cref="TraceEventData" /> object.</param>
        public override void TraceData(TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
        {
            if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, data, null))
            {
                return;
            }

            if (_tracesQueue.Count >= _maxQueueSize)
            {
                // No connection string
                if (--_remainingErrorsToLog > 0)
                {
                    RawLogger.LogWarning(ErrorCodes.Framework.ListenerFlooded, InternalMessages.FrameworkListenerFlooded);
                }
                return;
            }

            _tracesQueue.Enqueue(data as TraceEventData);
        }
예제 #6
0
        private void Begin(System.Diagnostics.TraceEventType type)
        {
            logEntityType = type;

            Timestamp = DateTime.Now;
            ProcessId = Process.GetCurrentProcess().Id;
            ThreadId  = Thread.CurrentThread.ManagedThreadId;
            switch (type)
            {
            case TraceEventType.Error:
                break;

            //case LogMode.Trace:
            //    Format(true);
            // break;
            default:
                Format(false);
                break;
            }
        }
예제 #7
0
 public override void TraceEvent(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType severity, int id, string format, params object[] args)
 {
 }
예제 #8
0
 public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType severity, int id, params object[] data)
 {
 }
예제 #9
0
 public override void TraceEvent(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType severity, int id, string message)
 {
 }
예제 #10
0
 /// <summary>
 /// Logs events with default trace.
 /// </summary>
 /// /// <param name="enumTraceEventType"></param>
 /// <param name="msg"></param>
 public static void Trace(System.Diagnostics.TraceEventType enumTraceEventType, string msg)
 {
     Logger.trace.TraceEvent(enumTraceEventType, 0, msg);
 }
예제 #11
0
 /// <summary>
 /// Logs events with default trace.
 /// </summary>
 /// /// <param name="enumTraceEventType"></param>
 /// <param name="format">Message with format.</param>
 /// /// <param name="parameters">string parameters to replace in the format string.</param>
 public static void Trace(System.Diagnostics.TraceEventType enumTraceEventType, string format, params string[] parameters)
 {
     Logger.trace.TraceEvent(enumTraceEventType, 0, string.Format(format, parameters));
 }
예제 #12
0
 public LogEventAttribute(System.Diagnostics.TraceEventType evtType, string fmt)
 {
     Message   = fmt;
     EventType = evtType;
 }
예제 #13
0
 public void TraceEvent(System.Diagnostics.TraceEventType eventType, int id, string format, params object[] args)
 {
 }
예제 #14
0
 public void Write(Exception exception, System.Diagnostics.TraceEventType severity)
 {
 }
예제 #15
0
 public void Write(string message, System.Diagnostics.TraceEventType severity)
 {
 }
예제 #16
0
 static public void Write(object message, int priority, int eventid, System.Diagnostics.TraceEventType severity, string title)
 {
     Write(message, priority, eventid, severity, title, null);
 }
예제 #17
0
        static public void Write(object message, int priority, int eventid, System.Diagnostics.TraceEventType severity, string title, LogCategory logCategory)
        {
            log4net.ILog log = null;
            log4net.Core.IAppenderAttachable appenders = null;

            try
            {
                Monitor.Enter(padlock);

                // Intialize the default settings.
                if (settings == null)
                {
                    try
                    {
                        // Initialize the log settings from the default appender configuration file.
                        IntializeLogSettings();

                        // Custom appenders are optional to support overriding the default configuration.
                        if (System.Configuration.ConfigurationManager.AppSettings["log4net_appenders_custom"] != null)
                        {
                            var custom = EnterpriseLibrary.Configuration.ConfigurationManager.GetConfiguration <LoggerConfiguration>("log4net_appenders_custom");

                            // Override the default settings with the defined custom values.
                            settings = custom.Merge(settings);
                        }

                        // Create the default logger and access its appender collection.
                        log       = log4net.LogManager.GetLogger(settings.CategoryName);
                        appenders = (log4net.Core.IAppenderAttachable)log.Logger;

                        if (settings.AppenderCollection != null)
                        {
                            // Create the appenders and add them to the loggers collection.
                            ManageAppenderCollection(settings.AppenderCollection.Appenders, appenders);
                        }
                        else
                        {
                            // No appenders were found. Create the appender(s) based on the defaults.
                            if (settings.DefaultAppenders != null)
                            {
                                CreateAppender(settings.DefaultAppenders.RollingFileAppender, appenders);
                                CreateAppender(settings.DefaultAppenders.ConsoleAppender, appenders);
                            }
                            else
                            {
                                throw new Exception("A default appender was not found. In order to support logging at least one default logger must be defined.");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // We were unable to initialize the settings without errors.
                        settings = null;

                        throw ex;
                    }
                }

                // CUSTOM LOG CATEGORY
                // If a log category is defined use it.
                if (logCategory != null && !string.IsNullOrEmpty(logCategory.Name))
                {
                    // Check to see if the category's logger already exists. If it does then the category's appenders have already been created.
                    if (log4net.LogManager.Exists(logCategory.Name) == null)
                    {
                        // Create the catgory's logger and it's appenders.
                        // GetLogger() will create the logger and add it to the repository if it does not already exist so we
                        // need to see if it exists before calling this method or we will not know that we need to create the appenders.
                        log       = log4net.LogManager.GetLogger(logCategory.Name);
                        appenders = (log4net.Core.IAppenderAttachable)log.Logger;

                        // Create the appenders.
                        ManageAppenderCollection(logCategory.Appenders, appenders);
                    }
                    else
                    {
                        // Get the customized logger.
                        log = log4net.LogManager.GetLogger(logCategory.Name);
                    }
                }

                // DEFAULT APPENDER
                // A log category was not provided so the default must be used.
                else
                {
                    // Get the default logger.
                    log = log4net.LogManager.GetLogger(settings.CategoryName);
                }

                // Write the log message to the file.
                switch (severity)
                {
                case TraceEventType.Information:
                    log.Info(message);
                    break;

                case TraceEventType.Error:
                    log.Error(message);
                    break;

                case TraceEventType.Warning:
                    log.Warn(message);
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Monitor.Exit(padlock);
            }
        }
예제 #18
0
 public void TraceEvent(System.Diagnostics.TraceEventType eventType, int id)
 {
 }
예제 #19
0
 public void TraceEvent(System.Diagnostics.TraceEventType eventType, int id, string message)
 {
 }
 public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
 {
 }
예제 #21
0
        public void Write(object message, ICollection <string> categories, int priority, int eventId, System.Diagnostics.TraceEventType severity, string title, IDictionary <string, object> properties)
        {
            var props = Utility.CollectAutoProperties(properties);

            Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(
                message ?? String.Empty, categories ?? Logger.EmptyCategoryList,
                priority, eventId, severity, title ?? string.Empty, props);
        }
예제 #22
0
 public void TraceData(System.Diagnostics.TraceEventType eventType, int id, params object[] data)
 {
 }
예제 #23
0
 public static void TraceEvent(System.Diagnostics.TraceEventType eventType, int id, string message)
 {
     Source.TraceEvent(eventType, id, message);
     Source.Flush();
 }
예제 #24
0
 public static void Log(string sMessage, System.Diagnostics.TraceEventType tet, int nLevel)
 {
     Log(sMessage, tet, Logger.LogLevel.Panic);
 }
예제 #25
0
 public LogEventAttribute(System.Diagnostics.TraceEventType evtType)
     : this(evtType, null)
 {
 }
예제 #26
0
 public override bool ShouldTrace(System.Diagnostics.TraceEventCache cache, string source, System.Diagnostics.TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data)
 {
     throw null;
 }
예제 #27
0
 public void Write(Exception exception, System.Diagnostics.TraceEventType severity, System.Collections.IDictionary items)
 {
 }
예제 #28
0
 /// <summary>
 /// Writes a message to a log with the given list of categories, priority, event id and severity.
 /// </summary>
 /// <remarks>
 /// Only writes to the log if logging is enabled, which can be verified through <see cref="IsLoggingEnabled"/>.
 /// </remarks>
 /// <param name="message">The message to be written to the log.</param>
 /// <param name="categories">The category related to the message.</param>
 /// <param name="priority">The priority of the message.</param>
 /// <param name="eventId">The event id of the message. Specially applicable for messages being logged to the Windows Event Log.</param>
 /// <param name="severity">The severity of the message.</param>
 public void Write(string message, IEnumerable <string> categories, LogPriority priority, int eventId, System.Diagnostics.TraceEventType severity)
 {
     Write(message, categories, priority, eventId, severity, this.Title);
 }
예제 #29
0
 public void Write(string message, System.Diagnostics.TraceEventType severity, System.Collections.IDictionary items)
 {
 }
예제 #30
0
 /// <summary>
 /// Writes a message to a log with the given list of categories, priority, event id, severity and title.
 /// </summary>
 /// <remarks>
 /// Only writes to the log if logging is enabled, which can be verified through <see cref="IsLoggingEnabled"/>.
 /// </remarks>
 /// <param name="message">The message to be written to the log.</param>
 /// <param name="categories">The category related to the message.</param>
 /// <param name="priority">The priority of the message.</param>
 /// <param name="eventId">The event id of the message. Specially applicable for messages being logged to the Windows Event Log.</param>
 /// <param name="severity">The severity of the message.</param>
 /// <param name="title">The title of the message.</param>
 public void Write(string message, IEnumerable <string> categories, LogPriority priority, int eventId, System.Diagnostics.TraceEventType severity, string title)
 {
     if (IsLoggingEnabled())
     {
         _writer.Write(message, categories, (int)priority, eventId, severity, title);
     }
 }