コード例 #1
0
 public LoggingActivityBuilder(ILoggingTarget target, string name, LoggingLevel level, LoggingOptions options)
 {
     _target  = target;
     _name    = name;
     _level   = level;
     _options = options;
 }
コード例 #2
0
        /// <summary>
        /// Initializes an MSMQ Logging Target
        /// </summary>
        /// <param name="logName">Enterprise library log name</param>
        /// <param name="queuePath">MSMQ path e.g., ".\\Private$\\NOC" (backslashes need to be escaped) </param>
        /// <param name="backupLog">Instance of the backup log used in case instantion fails.</param>
        /// <param name="priorities">One or more priorities that this target will log</param>
        public MSMQLog(string logName, string queuePath, ILoggingTarget backupLog,
                       params enumEventPriority [] priorities)
        {
            _priorities = priorities;
            _backupLog  = backupLog;

            try
            {
                _msmqLogger = new MsmqTraceListener(logName, queuePath, new TextFormatter(),
                                                    MessagePriority.Normal, true, TimeSpan.FromDays(1), TimeSpan.FromDays(1), false, true, false,
                                                    MessageQueueTransactionType.None);
            }
            catch (Exception ex)
            {
                string errMsg = string.Format("Could not create MSMQ Logger with queuePath: {0} errorMsg: {1} \r\n"
                                              , ex
                                              , queuePath);

                _backupLog.Write(errMsg
                                 , true
                                 , 0
                                 , 0
                                 , EventLogEntryType.Error
                                 , enumEventPriority.Critical);

                throw new ExceptionEvent(enumExceptionEventCodes.EventLogSourceCreateFailed, errMsg, ex);
            }
        }
コード例 #3
0
ファイル: Logger.cs プロジェクト: 666marat666/UltLogger
        public Logger(string name, ILoggingTarget target, bool isInfo = false, bool isDebug = false, bool traceAdditionalInfo = false)
        {
            this.Name = name;
            this.loggingTarget = target;

            this.isInfo = isInfo;
            this.isDebug = isDebug;
            this.traceAdditionalInfo = traceAdditionalInfo;

            this.loggingTarget.Init(this);
            Context = null;
        }
コード例 #4
0
ファイル: Log.cs プロジェクト: mbolt35/OpenSource
        public static void AddTarget(ILoggingTarget target)
        {
            if (target == null) {
                return;
            }

            List<string> filters = target.Filters;

            foreach (string key in _loggers.Keys) {
                if (CategoryMatchInFilterList(key, filters)) {
                    target.AddLogger(_loggers[key]);
                }
            }

            _targets.Add(target);
            if (_targetLevel == int.MaxValue || (int)target.Level < _targetLevel) {
                _targetLevel = (int)target.Level;
            } else if ((int)target.Level < _targetLevel) {
                _targetLevel = (int)target.Level;
            }
        }
コード例 #5
0
        /// <summary>
        /// Initializes a Windows Event Log target
        /// </summary>
        /// <param name="logName">Event Log Name</param>
        /// <param name="logSource">Event Log Source</param>
        /// <param name="backupLog">Instance of the backup log used in case instantion fails.</param>
        /// <param name="priorities">One or more priorities that this target will log</param>
        public WindowsEventLog(string logName, string logSource, ILoggingTarget backupLog, params enumEventPriority [] priorities)
        {
            _priorities = priorities;
            try
            {
                _backupLog = backupLog;

                if (!EventLog.SourceExists(logSource))
                {
                    EventLog.CreateEventSource(logSource, logName);
                }
            }
            catch (System.Security.SecurityException secExc)
            {
                _backupLog.Write(string.Format("Could not write Event EventLog; ErrorMsg: {0} "
                                               + "received because Source does not exist and could not be created.{3}"
                                               + " Operation requires Administrator user.  To create: execute command: "
                                               + " eventcreate /so {1} /L {2} /D SourceCreate /T Information /ID 1"
                                               , secExc.Message
                                               , logSource
                                               , logName
                                               , Environment.NewLine)
                                 , true
                                 , 0
                                 , 0
                                 , EventLogEntryType.Error
                                 , enumEventPriority.Critical);

                throw new ExceptionEvent(enumExceptionEventCodes.EventLogSourceCreateFailed
                                         , string.Format("Could not verify or create EventLog source: {0} for logName {1}."
                                                         + " Operation requires Administrator user.  To create: execute command: "
                                                         + " eventcreate /so {0} /L {1} /D SourceCreate /T Information /ID 1"
                                                         , logSource
                                                         , logName), secExc);
            }

            _eventLog = new EventLog(logName, Environment.MachineName, logSource);
        }
コード例 #6
0
ファイル: Log.cs プロジェクト: mbolt35/OpenSource
        public static void RemoveTarget(ILoggingTarget target)
        {
            if (target == null) {
                return;
            }

            List<string> filters = target.Filters;

            foreach (string key in _loggers.Keys) {
                if (CategoryMatchInFilterList(key, filters)) {
                    target.RemoveLogger(_loggers[key]);
                }

            }

            for (int j = 0; j < _targets.Count; j++) {
                if (target == _targets[j]) {
                    _targets.RemoveAt(j);
                    j--;
                }
            }

            ResetTargetLevel();
        }
コード例 #7
0
 private void DoSomething(ILoggingTarget logger)
 {
     logger.LogEvent("Did something");
 }
コード例 #8
0
 private void DoSomething(ILoggingTarget logger)
 {
     logger.LogEvent("Did something");
 }
コード例 #9
0
        private List <ILoggingTarget> BuildLoggingTargetsFromConfig(ILoggingTarget backupLog
                                                                    , LoggingElement loggingConfig)
        {
            List <ILoggingTarget> loggingTargets = new List <ILoggingTarget>();

            foreach (LoggingTargetElement logTarget in loggingConfig.LoggingTargets.Cast <LoggingTargetElement>())
            {
                string priorities = logTarget.Priorities;

                enumEventPriority[] eventPriorities = GetEvenPrioritiesFromString(priorities.ToLower());

                string targetType = logTarget.TargetType.ToLower();
                _configuredOptions.AppendFormat("Target: {0}{1}", logTarget.TargetType, Environment.NewLine);

                string logName = logTarget.LogName;

                switch (targetType)
                {
                case "windowseventlog":
                    loggingTargets.Add(new WindowsEventLog(logName,
                                                           logTarget.Params.GetParamValue(Constants.EventLogSource).ToString()
                                                           , backupLog, eventPriorities));
                    _configuredOptions.AppendFormat("Param: {0}; Value: {1}{2}"
                                                    , Constants.EventLogSource
                                                    , logTarget.Params.GetParamValue(Constants.EventLogSource)
                                                    , Environment.NewLine);
                    break;

                case "msmq":
                    loggingTargets.Add(new MSMQLog(logName,
                                                   logTarget.Params.GetParamValue(Constants.MSMQPath).ToString()
                                                   , backupLog, eventPriorities));
                    _configuredOptions.AppendFormat("Param: {0}; Value: {1}{2}"
                                                    , Constants.MSMQPath, logTarget.Params.GetParamValue(Constants.MSMQPath)
                                                    , Environment.NewLine);
                    break;

                case "file":
                    loggingTargets.Add(new FileLog(logName,
                                                   logTarget.Params.GetParamValue(Constants.LogFileDirectory).ToString(), eventPriorities));
                    _configuredOptions.AppendFormat("Param: {0}; Value: {1}{2}"
                                                    , Constants.LogFileDirectory
                                                    , logTarget.Params.GetParamValue(Constants.LogFileDirectory)
                                                    , Environment.NewLine);
                    break;

                case "memoryfile":
                    loggingTargets.Add(new MemoryFileLog(logName,
                                                         logTarget.Params.GetParamValue(Constants.LogFileNamePrefix).ToString(),
                                                         logTarget.Params.GetParamValue(Constants.LogFileDirectory).ToString(),
                                                         Int32.Parse(logTarget.Params.GetParamValue(Constants.LogFileSize).ToString())
                                                         , eventPriorities));
                    _configuredOptions.AppendFormat("Param: {0}; Value: {1}{2}"
                                                    , Constants.LogFileNamePrefix
                                                    , logTarget.Params.GetParamValue(Constants.LogFileNamePrefix)
                                                    , Environment.NewLine);
                    _configuredOptions.AppendFormat("Param: {0}; Value: {1}{2}"
                                                    , Constants.LogFileDirectory, logTarget.Params.GetParamValue(Constants.LogFileDirectory)
                                                    , Environment.NewLine);
                    _configuredOptions.AppendFormat("Param: {0}; Value: {1}{2}"
                                                    , Constants.LogFileSize, logTarget.Params.GetParamValue(Constants.LogFileSize)
                                                    , Environment.NewLine);
                    break;

                default:
                    throw new ExceptionEvent(enumExceptionEventCodes.InvalidParameterValue,
                                             "Unkown logging target string: " + targetType);
                }
            }

            return(loggingTargets);
        }
コード例 #10
0
 public void SetTarget(string name, ILoggingTarget target)
 {
     _targets[name] = target;
 }