예제 #1
0
 public void RemoveTarget(ILogTarget target)
 {
     if (_targets.Contains(target))
     {
         _targets.Remove(target);
     }
 }
        /// <summary>
        /// Instantiates and adds loggers from the configuration file.
        /// </summary>
        private void GetLoggers()
        {
            _loadedLoggers = new List <ProdLogger>();
            //LoggerParameters = new List<ProdLoggerParameters>();
            //if (LoadedLoggers == null || LoggerParameters[0].AssemblyPath == null)
            //{
            //    return;
            //}

            foreach (ProdLoggerParameters item in _currentConfig.LoggerParameters)
            {
                /* needs to be a valid ProdLogger that implements ILogger */
                string tempPath = item.AssemblyPath;
                if (tempPath == null)
                {
                    throw new ProdOperationException("Configuration file error: No logger assembly specified");
                }

                /* try to grab a logger */
                ILogTarget tst = InitializeLogger(tempPath, item.LoggerType);

                /* Set the parameters, then add it to list of loggers */
                _tempLogger = new ProdLogger(_currentConfig, tst);
                _loadedLoggers.Add(_tempLogger);
            }
        }
예제 #3
0
        public void Progress(int level, ILogTarget target, double progress, bool relative = false)
        {
            if (relative)
            {
                progress += m_job.Progress;
            }
            if (progress > 1.0)
            {
                progress = 1.0;
            }
            m_job.Progress = progress;
            double seconds; string text; LogOpt opt;

            if (m_job.Timer == null)
            {
                seconds = -1.0; opt = LogOpt.None;
                text    = String.Format(CultureInfo.InvariantCulture, "{0,6:F2}%", 100.0 * progress);
            }
            else
            {
                seconds = m_job.Timer.ElapsedMilliseconds * 0.001; opt = LogOpt.Timed;
                text    = String.Format(CultureInfo.InvariantCulture, "{0,6:F2}% {1,10:F3} s", 100.0 * progress, seconds);
            }
            target.Log(m_ti, new LogMsg(LogType.Progress, opt, level,
                                        (m_job.HierarchyLevel - 1) * m_indent, m_job.Message, -2, text));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Progress(m_ti, level, target, m_job.Message, progress, seconds);
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Adds an ILogTarget implementation.
 /// </summary>
 /// <param name="target">The target to add.</param>
 public static void AddLogTarget(ILogTarget target)
 {
     if (!_targets.Contains(target))
     {
         _targets.Add(target);
     }
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultLogger"/> class.
 /// </summary>
 /// <param name="name">The logger name.</param>
 /// <param name="defaultLogLevel">The default log level.</param>
 /// <param name="logTarget">The log appender.</param>
 /// <param name="logFormatter">The log formatter.</param>
 public DefaultLogger(string name, LogLevel defaultLogLevel, ILogTarget logTarget, ILogFormatter logFormatter)
 {
     _name            = name;
     _defaultLogLevel = defaultLogLevel;
     _logTarget       = logTarget;
     _logFormatter    = logFormatter;
 }
예제 #6
0
 public void Add(ILogTarget target)
 {
     lock (m_targetArrayLock)
     {
         m_targetArray = m_targetArray.WithAppended(target);
     }
 }
예제 #7
0
 public void Remove(ILogTarget target)
 {
     lock (m_targetArrayLock)
     {
         m_targetArray = m_targetArray.WithRemoved(target);
     }
 }
예제 #8
0
        /// <summary>
        /// Registers a logger in this logging environment
        /// </summary>
        /// <param name="target">the target logger on which to forward log events</param>
        public static void RegisterLogTarget(ILogTarget target)
        {
            List <ILogTarget> targetList = null;
            var logZone = TryGetLoggingZone();

            if (logZone == null)
            {
                targetList = logTargets;
            }
            else
            {
                if (!zoneLoggers.TryGetValue(logZone, out targetList))
                {
                    targetList = logTargets;
                }
            }

            lock (targetList)
            {
                targetList.Add(target);
                void DispHandler(object sender, EventArgs args)
                {
                    lock (targetList)
                    {
                        targetList.Remove(target);
                    }

                    ((ILogTarget)sender).Disposed -= DispHandler;
                };

                target.Disposed += DispHandler;
            }
        }
예제 #9
0
        public void Text(int level, ILogTarget target, string text)
        {
            string[] lines = text.Split('\n');
            var      last  = lines.Length - 1;

            if (last == 0)
            {
                target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join, level,
                                            m_job.HierarchyLevel * m_indent, lines[0], -2));
            }
            else
            {
                for (int i = 0; i < last; i++)
                {
                    target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join | LogOpt.EndLine, level,
                                                m_job.HierarchyLevel * m_indent, lines[i]));
                }
                if (lines[last].Length > 0)
                {
                    target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join, level,
                                                m_job.HierarchyLevel * m_indent, lines[last]));
                }
            }
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Text(m_ti, level, target, text);
                }
            }
        }
        private IJobReporter CurrentReporter(ILogTarget target = null)
        {
            IJobReporter reporter;
            var          threadId  = Thread.CurrentThread.ManagedThreadId;
            bool         lockTaken = false;

            try
            {
                m_lock.Enter(ref lockTaken);
                if (!m_reporterMap.TryGetValue(threadId, out reporter))
                {
                    var threadIndex = m_threadCount++;
                    reporter = new JobReporter(threadIndex)
                    {
                        Indent = m_indent
                    };
                    m_reporterMap[threadId] = reporter;
                    if (target != null)
                    {
                        target.NewThreadIndex(threadIndex);
                    }
                }
            }
            finally
            {
                if (lockTaken)
                {
                    m_lock.Exit(true);
                }
            }
            return(reporter);
        }
예제 #11
0
        public AsyncLogTargetWrapper(ILogTarget target, int queueLimit, AsyncLogTargetOverflowAction overflowAction)
        {
            _target          = target;
            _messageQueue    = new BlockingCollection <LogEventArgs>(queueLimit);
            _overflowTimeout = overflowAction == AsyncLogTargetOverflowAction.Block ? -1 : 0;

            _messageThread = new Thread(() => {
                while (!_messageQueue.IsCompleted)
                {
                    try
                    {
                        _target.Log(this, _messageQueue.Take());
                    }
                    catch (InvalidOperationException)
                    {
                        // IOE means that Take() was called on a completed collection.
                        // Some other thread can call CompleteAdding after we pass the
                        // IsCompleted check but before we call Take.
                        // We can simply catch the exception since the loop will break
                        // on the next iteration.
                    }
                }
            });

            _messageThread.IsBackground = true;
            _messageThread.Start();
        }
예제 #12
0
        /// <summary>
        /// Verifies that the logger assembly implements ILogTarget.
        /// </summary>
        /// <param name="filename">The file path to the logger dll to be added.</param>
        /// <returns>
        ///   <c>true</c> if this is a valid target. <c>false</c> otherwise
        /// </returns>
        private static bool VerifyValidLoggerAssembly(string filename)
        {
            Assembly logAsm = Assembly.LoadFile(filename);

            foreach (Type item in logAsm.GetTypes())
            {
                /* Run through any interfaces this logger may implement..we want the ILogTarget */
                Type[] iface = item.GetInterfaces();
                if (iface.Length == 0)
                {
                    return(false);
                }

                foreach (Type t in iface)
                {
                    if (iface[0] != typeof(ILogTarget))
                    {
                        continue;
                    }

                    /* Create a temporary version of the logger to get any parameters */
                    ILogTarget tempLogger = (ILogTarget)Activator.CreateInstance(item);
                    /* Call the interface method to get info */
                    tempLogger.CallParameterForm();

                    return(true);
                }
            }
            return(false);
        }
예제 #13
0
        public ReportJob Begin(ReportJob parentJob, int level, ILogTarget target, string text, bool timed, bool noLog = false)
        {
            if (parentJob == null)
            {
                parentJob = m_job;
            }
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Begin(m_ti, level, target, text, timed);
                }
            }
            var opt = timed ? LogOpt.Timed : LogOpt.None;

            if (!noLog)
            {
                target.Log(m_ti, new LogMsg(LogType.Begin, opt, level, parentJob.HierarchyLevel * m_indent, text, -2));
            }
            m_jobStack.Push(m_job);
            m_job = new ReportJob(text, level, timed, parentJob);
            return(m_job);
        }
예제 #14
0
 /// <summary>
 /// Add a custom target
 /// </summary>
 /// <param name="target">Target to add</param>
 public void AddTarget(ILogTarget target)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     Targets.Add(target);
 }
예제 #15
0
 public KataLogPlayerNotifier(ILogTarget logTarget)
 {
     if (logTarget == null)
     {
         throw new ArgumentNullException("logTarget");
     }
     _logTarget = logTarget;
 }
예제 #16
0
 /// <summary>
 /// Creates a ProdLogger.
 /// </summary>
 /// <param name="target">The target logger.</param>
 /// <param name="logLevel">The log level.</param>
 /// <param name="logFormat">The log format.</param>
 /// <param name="logDateFormat">The log date format.</param>
 /// <returns>A new ProdLogger</returns>
 /// <remarks>
 /// This provides a way for someone to create a new logger on the fly
 /// </remarks>
 public ProdLogger(ILogTarget target, LoggingLevels logLevel, string logFormat, string logDateFormat)
 {
     LogLevel      = logLevel;
     _loggerParams = null;
     LogFormat     = logFormat;
     LogDateFormat = logDateFormat;
     LogTarget     = target;
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProdLogger"/> class.
 /// </summary>
 /// <param name="config">The configuration loaded from a .ses file.</param>
 /// <param name="target">The target logger interface.</param>
 public ProdLogger(LoggingConfiguration config, ILogTarget target)
 {
     LogLevel      = (LoggingLevels)config.LoggerParameters[0].LogLevel;
     _loggerParams = config.LoggerParameters[0].Parameters;
     LogFormat     = config.LoggerParameters[0].LogFormat;
     LogDateFormat = config.LoggerParameters[0].LogDateFormat;
     LogTarget     = target;
 }
예제 #18
0
        private KataLogPlayerNotifier CreateNotifier(ILogTarget logTarget = null)
        {
            logTarget = logTarget ?? Substitute.For <ILogTarget>();
            var loggingNotifier = new KataLogPlayerNotifier(logTarget);

            _itemsToDispose.Push(loggingNotifier);
            return(loggingNotifier);
        }
예제 #19
0
파일: Log.cs 프로젝트: nerai/Nibbler
 public static void AddTarget(ILogTarget t)
 {
     lock (_TargetsLock) {
         var list = new List <ILogTarget> (_Targets);
         list.Add(t);
         _Targets = list;
     }
 }
예제 #20
0
파일: Log.cs 프로젝트: nerai/Nibbler
 public static void RemoveTarget(ILogTarget t)
 {
     lock (_TargetsLock) {
         var list = new List <ILogTarget> (_Targets);
         list.Remove(t);
         _Targets = list;
     }
 }
        /// <summary>
        /// Add a target
        /// </summary>
        /// <param name="target">Target to add</param>
        public void Add(ILogTarget target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            _configuration.AddInternal(target);
        }
예제 #22
0
 public LogService(ILogTarget target)
 {
     disposedValue  = false;
     this.target    = target ?? new DebugTarget();
     lockPublish    = new object();
     log            = new Subject <LogItem>();
     loggerObserver = log;
     SubscribeToLog();
 }
예제 #23
0
        /// <summary>
        /// Adds an ILogTarget to the LogService
        /// </summary>
        /// <param name="target">The ILogTarget to add</param>
        public static void AddTarget(ILogTarget target)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            if (_logTargets == null)
                _logTargets = new List<ILogTarget>();

            if (!_logTargets.Contains(target))
                _logTargets.Add(target);
        }
예제 #24
0
        /// <summary>
        /// Called by <see cref="FluentTargetConfigurationTypes"/> for each defined target
        /// </summary>
        /// <param name="target">Target to add</param>
        internal void AddInternal(ILogTarget target)
        {
            _currentTarget = target;
            if (_targets.ContainsKey(target.Name))
            {
                return;
            }

            _targets.Add(target.Name, target);
        }
예제 #25
0
 /// <summary>
 /// Change the Target to write. After call this method you must get Current again.
 /// </summary>
 /// <example>
 /// <code>
 /// logService = Log.Current;
 /// //[...]
 /// Log.SetLogTargetAndRestartLog(new LogTarget());
 /// logService = Log.Current;
 /// </code>
 /// </example>
 /// <param name="target">New target for writing log.</param>
 public static ILogService SetLogTargetAndRestartLog(ILogTarget target)
 {
     logTarget = target;
     logService?.Dispose();
     logService = new LogService(logTarget);
     if (usingSplat)
     {
         Locator.CurrentMutable.RegisterConstant(Current);
     }
     return(logService);
 }
예제 #26
0
        /// <summary>
        /// Constructor used for create child
        /// </summary>
        /// <param name="config">Top level logger config</param>
        /// <param name="logQueue">Global stream listener</param>
        /// <param name="factory">Factory to create additional logger</param>
        /// <param name="targetType">Type this logger is assigned to</param>
        /// <param name="logTarget">Existing log instance for loggers of same name</param>
        private Logger(ModuleLoggerConfig config, Type targetType, ILogTargetFactory factory, ILogTarget logTarget, BlockingCollection <LogMessage> logQueue)
        {
            _config           = config;
            _logTargetFactory = factory;
            _hostName         = targetType.Name;
            _targetLog        = logTarget ?? factory.Create(_config.LoggerName);
            LogQueue          = logQueue;

            // Put this instance to the clone cache for later reuse.
            _cloneCache[_hostName] = this;
        }
예제 #27
0
        public IEnumerable <ILogTarget> GetAllLogTargets()
        {
            _rwLock.AcquireReaderLock(0);

            var arr = new ILogTarget[LogTargets.Count];

            arr.CopyTo(arr, 0);

            _rwLock.ReleaseReaderLock();

            return(arr);
        }
예제 #28
0
        public void Line(LogType type, int level, ILogTarget target, string t0, int p1 = 0, string t1 = null)
        {
            target.Log(m_ti, new LogMsg(type, LogOpt.EndLine, level, m_job.HierarchyLevel * m_indent, t0, p1, t1));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Line(m_ti, type, level, target, t0, p1, t1);
                }
            }
        }
예제 #29
0
        public static void RemoveTarget(string target)
        {
            ILogTarget logTarget = GetTarget(target);

            if (logTarget != null)
            {
                Updated -= logTarget.Log;

                m_LogTargets.Remove(logTarget);

                logTarget.Dispose();
            }
        }
예제 #30
0
        public void Wrap(int level, ILogTarget target, string text)
        {
            target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join | LogOpt.Wrap, level,
                                        m_job.HierarchyLevel * m_indent, text, -2));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Wrap(m_ti, level, target, text);
                }
            }
        }
예제 #31
0
        public void Values(int level, ILogTarget target, string name, string separator, object[] values)
        {
            var text = values.Length == 1 ? values[0].ToString() : values.Map(o => o.ToString()).Join(separator);

            target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.EndLine, level,
                                        m_job.HierarchyLevel * m_indent, name, 40, text));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Values(m_ti, level, target, name, separator, values);
                }
            }
        }
예제 #32
0
 public bool DetachLogTarget(ILogTarget logTarget)
 {
     try
     {
         rwlLogTargetList.AcquireWriterLock(Timeout.Infinite);
         try
         {
             allLogTarget.Remove(logTarget);
             return true;
         }
         catch
         {
             return false;
         }
         finally
         {
             rwlLogTargetList.ReleaseWriterLock();
         }
     }
     catch
     {
         return false;
     }
 }
예제 #33
0
파일: Logger.cs 프로젝트: Donnotron666/BEEP
		public Logger (string logName, ILogTarget[] targets)
		{
			this.LogName = logName;
			Targets = targets;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentFilterConfiguration"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="logTarget">The log target.</param>
 public FluentFilterConfiguration(FluentTargetConfiguration configuration, ILogTarget logTarget)
 {
     _configuration = configuration;
     _logTarget = logTarget;
 }
예제 #35
0
 /// <summary>
 /// Add a custom target
 /// </summary>
 /// <param name="target">Target to add</param>
 public void AddTarget(ILogTarget target)
 {
     if (target == null) throw new ArgumentNullException("target");
     Targets.Add(target);
 }
		/// <summary>
		/// Adds a custom log target
		/// </summary>
		/// <param name="target">Log target</param>
		public void AddLogTarget(ILogTarget target)
		{
			_targets.Add(target);
		}
예제 #37
0
		/*============================================================================*/
		/* Constructor                                                                */
		/*============================================================================*/

		/// <summary>
		/// Creates a new logger
		/// </summary>
		/// <param name="source">The log source object</param>
		/// <param name="target">The log target</param>
		public Logger (object source, ILogTarget target)
		{
			_source = source;
			_target = target;
		}
예제 #38
0
        private void CreatePacketLog(LoggerConfiguration config, ILogTarget target)
        {
            try
            {
                var filePath = FileHelpers.GetAbsolutePath(string.Format("{0}/{1}", _rootFolder, target.Filename));

                if (target.Rolling)
                    config.WriteTo.RollingFile(filePath, target.Level, FileLogFormat);
                else
                    config.WriteTo.File(filePath, target.Level, FileLogFormat);
            }
            catch (UnauthorizedAccessException e)
            {
                Log.ForContext<LogManager>().Error("Error creating file log {0:l} - {1:l}", target.Filename, e.Message);
            }
        }
예제 #39
0
        /// <summary>
        /// Selects a new ILogTarget to log to TODO: |f| might want to add a feature to carry over existing logs
        /// </summary>
        public static void SelectSingleTarget(ILogTarget target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            DisposeTargets();
            _logTargets = new List<ILogTarget>();       // no need to check for null since we want to replace the whole list

            _logTargets.Add(target);
        }
예제 #40
0
        private void CreatePacketLog(LoggerConfiguration config, ILogTarget target)
        {
            string filePath = string.Format("{0}/{1}", _rootFolder, target.Filename);

            if (target.Rolling)
                config.WriteTo.RollingFile(filePath, target.Level, FileLogFormat);
            else
                config.WriteTo.File(filePath, target.Level, FileLogFormat);
        }
예제 #41
0
 /// <summary>
 ///     Registers the specified <see cref="ILogTarget" /> within the builder
 /// </summary>
 public void AddTarget(ILogTarget target)
 {
     _guard.AgainstNullArgument(nameof(target), target);
     _targets.Add(target);
 }
        /// <summary>
        /// Called by <see cref="FluentTargetConfigurationTypes"/> for each defined target
        /// </summary>
        /// <param name="target">Target to add</param>
        internal void AddInternal(ILogTarget target)
        {
            _currentTarget = target;
            if (_targets.ContainsKey(target.Name))
                return;

            _targets.Add(target.Name, target);
        }
예제 #43
0
 private void CreateConsoleLog(LoggerConfiguration config, ILogTarget target)
 {
     config.WriteTo.ColoredConsole(target.Level, ConsoleLogFormat);
 }
 /// <summary>
 /// Add a target
 /// </summary>
 /// <param name="target">Target to add</param>
 public void Add(ILogTarget target)
 {
     Contract.Requires(target != null);
     _configuration.AddInternal(target);
 }
예제 #45
0
 public void Unchain(ILogTarget target)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Add a target
        /// </summary>
        /// <param name="target">Target to add</param>
        public void Add(ILogTarget target)
        {
            if (target == null) throw new ArgumentNullException("target");

            _configuration.AddInternal(target);
        }