Пример #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ExternalLogListener"/>.
		/// </summary>
		/// <param name="logger">External recipient of messages.</param>
		public ExternalLogListener(ILogListener logger)
		{
			if (logger == null)
				throw new ArgumentNullException(nameof(logger));

			Logger = logger;
		}
Пример #2
0
        static RippleLog()
        {
            Listeners = new List<ILogListener>();
            File = new FileListener();

            Reset();
        }
        // ReSharper disable UseObjectOrCollectionInitializer
        private ConsoleRedirector(ILogListener logListener)
        {
            bool ret;
            AnonymousPipeClientStream client;

            _logListener = logListener;
            _stdout = GetStdHandle(STD_OUTPUT_HANDLE);
            _stderr = GetStdHandle(STD_ERROR_HANDLE);
            _sync = new Mutex();
            _buffer = new char[BUFFER_SIZE];

            _outServer = new AnonymousPipeServerStream(PipeDirection.Out);
            client = new AnonymousPipeClientStream(PipeDirection.In, _outServer.ClientSafePipeHandle);
            //client.ReadTimeout = 0;
            Debug.Assert(_outServer.IsConnected);
            _outClient = new StreamReader(client, Encoding.Default);
            ret = SetStdHandle(STD_OUTPUT_HANDLE, _outServer.SafePipeHandle.DangerousGetHandle());
            Debug.Assert(ret);

            _errServer = new AnonymousPipeServerStream(PipeDirection.Out);
            client = new AnonymousPipeClientStream(PipeDirection.In, _errServer.ClientSafePipeHandle);
            //client.ReadTimeout = 0;
            Debug.Assert(_errServer.IsConnected);
            _errClient = new StreamReader(client, Encoding.Default);
            ret = SetStdHandle(STD_ERROR_HANDLE, _errServer.SafePipeHandle.DangerousGetHandle());
            Debug.Assert(ret);

            Thread outThread = new Thread(doRead);
            Thread errThread = new Thread(doRead);
            outThread.Name = "stdout logger";
            errThread.Name = "stderr logger";
            outThread.Start(_outClient);
            errThread.Start(_errClient);
            _timer = new Timer(flush, null, PERIOD, PERIOD);
        }
Пример #4
0
		/// <summary>
		/// Создать <see cref="GuiLogListener"/>.
		/// </summary>
		/// <param name="listener">Визуальный компонент, для которого требуется синхронизация с GUI потоков при записи новых сообщений <see cref="LogMessage"/>.</param>
		public GuiLogListener(ILogListener listener)
		{
			if (listener == null)
				throw new ArgumentNullException("listener");

			_listener = listener;
		}
Пример #5
0
        private const int ENTRY_HEADER_SIZE = 20; // 2*2 + 4*4; see LogEntry.

        #endregion Fields

        #region Constructors

        public LogReceiver( ILogListener listener )
        {
            EntryDataOffset = 0;
            EntryHeaderBuffer = new byte[ENTRY_HEADER_SIZE];
            EntryHeaderOffset = 0;
            Listener = listener;
        }
Пример #6
0
 public virtual void Unregister(ILogListener listener)
 {
     lock (SyncRoot)
     {
         if (!Listeners.Contains(listener))
             return;
         Listeners.Remove(listener);
     }
 }
Пример #7
0
        static RippleLog()
        {
            Listeners = new List<ILogListener>();

            RegisterListener(new RippleLogger());
            File = new FileListener();

            AddFileListener();
        }
Пример #8
0
 public virtual void Register(ILogListener listener)
 {
     lock (SyncRoot)
     {
         if (Listeners.Contains(listener))
             return;
         if (listener.Parents != null)
             listener.Parents.Add(this);
         Listeners.Add(listener);
     }
 }
Пример #9
0
 void Queue_Process(object sender, ProcessQueueEventArgs<LogQueueItem> e)
 {
     ILogListener[] listeners;
     lock (SyncRoot)
     {
         listeners = new ILogListener[Listeners.Count];
         Listeners.CopyTo(listeners);
     }
     foreach (var listener in listeners)
     {
         if ((listener.Level & e.Item.Level) != 0 && listener.LogFunc != null)
         {
             listener.LogFunc(e.Item.Level, e.Item.Object);
         }
     }
 }
Пример #10
0
		public ThemaFactory(
			IThemaLoader loader = null,
			IRoleResolver roleresolver = null,
			IFileNameResolver fileresolver = null,
			ITypeLocator locator = null,
			IEntityResolver entityResolver = null,
			ILogListener log = null,
			IPeriodProvider periodprovider = null) {
			Themas = new ThemaCollection {Factory = this};
			RoleResolver = roleresolver ?? QWebServiceRegistry.Default.RoleResolver;
			FileResolver = fileresolver ?? QWebServiceRegistry.Default.FileNameResolver;
			TypeLocator = locator ?? QWebServiceRegistry.Default.TypeLocator;
			PeriodProvider = periodprovider ?? TypeLocator.Get<IPeriodProvider>().create<IPeriodProvider>();
			EntityResolver = entityResolver ?? TypeLocator.Get<IEntityResolver>().create<IEntityResolver>();
			Sources = new List<IThemaSource>();
			Log = log ?? QWebServiceRegistry.Default.Log;
			Loader = loader ?? new Loader(this);
		}
Пример #11
0
 public AddLogListenerCommand(ILogListener info)
 {
     Listener = info;
 }
Пример #12
0
        private void UnsubscribeLogListener()
        {
            if (_logListener == null)
            {
                return;
            }

            LogManager.RemoveListener(_logListener);
            _logListener.LogMessage -= OnLogMessage;

            _logListener = null;
        }
Пример #13
0
 public RemoveLogListenerCommand(ILogListener info)
 {
     Listener = info;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExternalLogListener"/>.
 /// </summary>
 /// <param name="logger">External recipient of messages.</param>
 public ExternalLogListener(ILogListener logger)
 {
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Пример #15
0
 /// <summary>
 /// Keep reading log messages until cancelled by the listener or closed.
 /// </summary>
 public void RunLogService(ILogListener listener, IDevice device, string logName)
 {
     using (var socket = new AdbRequest(EndPoint))
     {
         socket.RunLogService(listener, device, logName);
     }            
 }
Пример #16
0
        /// <summary>
        /// Adds a log listener which will receive all log events.
        /// <para />
        /// This method does not check whether the <paramref name="listener"/> is already added to the list
        /// of registered listeners.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="listener"/> is <c>null</c>.</exception>
        public static void AddListener(ILogListener listener)
        {
            Argument.IsNotNull("listener", listener);

            lock (_logListeners)
            {
                _logListeners.Add(listener);

                LogInfo.UpdateLogInfo();

                Log.Debug("Added listener '{0}' to log manager", listener.GetType().FullName);
            }
        }
Пример #17
0
        /// <summary>
        /// Determines whether the specified listener is already registered or not.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <returns>
        /// 	<c>true</c> if the specified listener is already registered; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="listener"/> is <c>null</c>.</exception>
        public static bool IsListenerRegistered(ILogListener listener)
        {
            Argument.IsNotNull("listener", listener);

            lock (_logListeners)
            {
                return _logListeners.Contains(listener);
            }
        }
Пример #18
0
 public OpsErrorLogger(ILogListener _listener)
 {
     listener = _listener;
     Ops.Logger.ExceptionLogger.AddLogger(this);
 }
Пример #19
0
 public static void AddListener(ILogListener listener)
 {
     _listeners.Add(listener);
 }
Пример #20
0
        private void SubscribeLogListener()
        {
            if (!_isViewModelActive)
            {
                return;
            }

            var logListenerType = LogListenerType;
            if (logListenerType == null)
            {
                return;
            }

            if (logListenerType == typeof(LogViewerLogListener))
            {
                _logListener = _logViewerLogListener;

                AddLogEntries(_logViewerLogListener.GetLogEntries(), true);
            }
            else
            {
                _logListener = _typeFactory.CreateInstance(logListenerType) as ILogListener;
                if (_logListener != null)
                {
                    LogManager.AddListener(_logListener);
                }
            }

            if (_logListener != null)
            {
                _logListener.IgnoreCatelLogging = IgnoreCatelLogging;
                _logListener.LogMessage += OnLogMessage;
            }
        }
Пример #21
0
 public static void Register(ILogListener listener)
 {
     Instance.mListeners.Add(listener);
 }
Пример #22
0
        private void UnsubscribeLogListener()
        {
            if (_logListener == null)
            {
                return;
            }

            if (!(_logListener is LogViewerLogListener))
            {
                LogManager.RemoveListener(_logListener);
            }

            _logListener.LogMessage -= OnLogMessage;
            _logListener = null;
        }
Пример #23
0
 public static void Unregister(ILogListener listener) { Logger.Instance.Unregister(listener); }
 /// <summary>
 /// Adds a log listener to the logger.
 /// Log listeners receive log messages from other sources, then 
 /// pass them on to their registered logger.
 /// </summary>
 /// <param name="logListener"></param>
 public void AddLogListener(ILogListener logListener)
 {
     //add log writer to list
     if (!(_logListeners.ContainsKey(logListener.LogListenerID)))
         _logListeners.Add(logListener.LogListenerID, logListener);
 }
Пример #25
0
 public static void RegisterListener(ILogListener listener)
 {
     Listeners.Add(listener);
 }
 public static void attach(ILogListener listener)
 {
     Debug.Assert(null == _instance);
     _instance = new ConsoleRedirector(listener);
 }
Пример #27
0
        public static void RegisterMethodLogAsyncInterceptor(this Container container, ILogListener logListener)
        {
            if (logListener == null)
            {
                throw new ArgumentException();
            }

            container.Register <MethodLogAsyncInterceptor>();
            container.Register <ILogger, Logger>();
            container.RegisterSingleton(() => logListener);
            container.RegisterInitializer <Logger>(logger => logger.Attach(container.GetInstance <ILogListener>()));
            container.Register(() => CreateMethodLogMessageFactory(container));
            container.Register <ILogMessageSettings, LogMessageSettings>();
            container.Register <ILogValueMapper, LogValueMapper>();
            container.Register <ILogValueMapperConfigurator, DefaultLogValueMapperConfigurator>();
        }
Пример #28
0
        /// <summary>
        /// Keep reading log messages until cancelled by the listener or closed.
        /// </summary>
        internal void RunLogService(ILogListener listener, IDevice device, string logName)
        {
            // Connect to the given device
            SetDevice(device);

            // Send request
            Write(FormatAdbRequest("log:" + logName));

            // Read response
            var resp = ReadAdbResponse(false);
            if (!resp.Okay)
            {
                throw new AdbCommandRejectedException(resp.Message);
            }

            var data = new byte[16384];
            var receiver = new LogOutputReceiver(listener);
            while (true)
            {
                if (receiver.IsCancelled)
                {
                    break;
                }

                var count = tcpClient.GetStream().Read(data, 0, data.Length);
                if (count == 0)
                {
                    // we're at the end, we flush the output
                    break;
                }
                // send data to receiver 
                receiver.AddOutput(data, 0, count);
            }
        }
Пример #29
0
        /// <summary>
        /// Removes the a log listener which will stop receiving all log events.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="listener"/> is <c>null</c>.</exception>
        public static void RemoveListener(ILogListener listener)
        {
            Argument.IsNotNull("listener", listener);

            lock (_logListeners)
            {
                _logListeners.Remove(listener);

                LogInfo.UpdateLogInfo();

                Log.Debug("Removed listener '{0}' from log manager", listener.GetType().FullName);
            }
        }
Пример #30
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public LogOutputReceiver(ILogListener listener)
 {
     if (listener == null)
         throw new ArgumentNullException("listener");
     this.listener = listener;
 }
Пример #31
0
        /// <summary>
        /// Determines whether the specified listener is interested in the log event.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <param name="logEvent">The log event.</param>
        /// <returns>
        /// <c>true</c> if the specified listener is interested in the log event; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="listener"/> is <c>null</c>.</exception>
        private static bool IsListenerInterested(ILogListener listener, LogEvent logEvent)
        {
            Argument.IsNotNull("listener", listener);

            switch (logEvent)
            {
                case LogEvent.Debug:
                    return listener.IsDebugEnabled;

                case LogEvent.Info:
                    return listener.IsInfoEnabled;

                case LogEvent.Warning:
                    return listener.IsWarningEnabled;

                case LogEvent.Error:
                    return listener.IsErrorEnabled;

                default:
                    throw new ArgumentOutOfRangeException("logEvent");
            }
        }
Пример #32
0
        private void SubscribeLogListener()
        {
            if (!_isViewModelActive)
            {
                return;
            }

            var logListenerType = LogListenerType;
            if (logListenerType == null)
            {
                return;
            }

            _logListener = _typeFactory.CreateInstance(logListenerType) as ILogListener;
            if (_logListener != null)
            {
                _logListener.IgnoreCatelLogging = IgnoreCatelLogging;
                _logListener.LogMessage += OnLogMessage;

                LogManager.AddListener(_logListener);
            }
        }
Пример #33
0
 /// <summary>
 /// Creates a <seealso cref="LogReceiver"/> with an <seealso cref="ILogListener"/>.
 /// <p/>
 /// The <seealso cref="ILogListener"/> will receive new log entries as they are parsed, in the form
 /// of <seealso cref="LogEntry"/> objects. </summary>
 /// <param name="listener"> the listener to receive new log entries. </param>
 public LogReceiver(ILogListener listener)
 {
     mListener = listener;
 }
Пример #34
0
 /// <summary>removes a listener from the log engine</summary>
 /// <param name="listener">listener to remove</param>
 public void RemoveListnener(ILogListener listener)
 {
     _Listeners.Remove(listener);
 }