Пример #1
0
 protected override void Log(LoggerLevel loggerLevel, string loggerName, string message, Exception exception)
 {
    System.Diagnostics.Debug.WriteLine("[{0}] {1}", loggerLevel, message);
    if (exception == null)
       return;
    System.Diagnostics.Debug.WriteLine("[{0}] {1}: {2} {3}", loggerLevel, exception.GetType().FullName, exception.Message, exception.StackTrace);
 }
 static void WriteLine(LoggerLevel level, string message)
 {
     ConsoleColor color = ConsoleColor.White;
     switch (level)
     {
         case LoggerLevel.Info:
             color = ConsoleColor.Green;
             break;
         case LoggerLevel.Debug:
             color = ConsoleColor.White;
             break;
         case LoggerLevel.Warn:
             color = ConsoleColor.Yellow;
             break;
         case LoggerLevel.Error:
             color = ConsoleColor.Red;
             break;
         default:
             break;
     }
     if (WaitForInput)
     {
         message = Environment.NewLine + message;
     }
     Console.ForegroundColor = color;
     Console.WriteLine(message);
     Console.ResetColor();
     if (WaitForInput)
     {
         Console.Write(Prefix);
     }
 }
 public BackgroundWorkerService(string sitesPath, string executablePath, ILoggerFactory loggerFactory, LoggerLevel logLevel)
 {
     _executablePath = executablePath;
     _executables = new Dictionary<string, List<Executable>>();
     _executableFinder = new ExecutableFinder(sitesPath);
     _logger = loggerFactory.Create(GetType(), logLevel);
 }
		public override ILogger Create(string name, LoggerLevel level)
		{
			StreamLogger logger =
				new StreamLogger(name, new FileStream(name + ".log", FileMode.Append, FileAccess.Write), Encoding.Default);
			logger.Level = level;
			return logger;
		}
Пример #5
0
 public static void SetLogLevel(LoggerLevel logLevel)
 {
     lock (lockObject)
     {
         maxLogLevel = logLevel;
     }
 }
Пример #6
0
 public IISManager(string localSitesPath, string tempSitesPath, ISyncStatusRepository syncStatusRepository, ILoggerFactory loggerFactory, LoggerLevel logLevel)
 {
     _syncStatusRepository = syncStatusRepository;
     _localSitesPath = localSitesPath;
     _tempSitesPath = tempSitesPath;
     _logger = loggerFactory.Create(GetType(), logLevel);
 }
Пример #7
0
        public void Log(String logMessage, LoggerLevel messageLevel, params ComponentType[] messageComponentTypes)
        {
            if (messageLevel < _logThreshholdLevel) { return; }

            string date = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
            string level = messageLevel == LoggerLevel.NULL ? "   " : messageLevel.ToString();
            string type = messageComponentTypes[0] == ComponentType.NULL ? "   " : ComponentTypeUtil.GetCodeFromType(messageComponentTypes[0]);

            // If no component types are specified, log everything.
            if (componentTypesToLog == null || componentTypesToLog.Count == 0)
            {
                _streamWriter.WriteLine(date + " | " + level + " | " + type + " | " + logMessage);
                _streamWriter.Flush();
                return;
            }
            else // Else, only log messages matching one of the specified component types.
            {
                foreach (ComponentType componentType in messageComponentTypes)
                {
                    if (componentTypesToLog.Contains(componentType))
                    {
                        _streamWriter.WriteLine(date + " | " + level + " | " + type + " | " + logMessage);
                        _streamWriter.Flush();
                        return;
                    }
                }
            }
        }
Пример #8
0
        public override void Write(string logText, LoggerLevel loggerLevel, string source = "", string category = "", string metaData = "")
        {
            lock (this)
            {
                var useSource = string.Format(
                    "{0}{1}{2}",
                    GlobalSource,
                    (GlobalSource != "" & source != "" ? ":" : ""),
                    source);

                var dateString = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");

                _file.WriteLine(
                    "{0}|{1}|{2}|{3}|{4}",
                    dateString,
                    useSource,
                    loggerLevel,
                    metaData,
                    logText);

                if (FlushAfterEachWrite)
                {
                    _file.Flush();
                }
            }
        }
Пример #9
0
 /// <summary>
 /// Instantiates an Azure Web Farm Role.
 /// </summary>
 /// <param name="logFactory">The Castle.Core Logger Factory to use for logging, AzureDiagnosticsTraceListenerFactory by default</param>
 /// <param name="loggerLevel">The Castle.Core Log Level to use for logging, LoggerLevel.Info by default</param>
 /// <param name="diagnosticsLogLevel">The log level to use for Azure Diagnostics, LogLevel.Information by default</param>
 public WebFarmRole(ILoggerFactory logFactory = null, LoggerLevel? loggerLevel = null, LogLevel? diagnosticsLogLevel = null)
 {
     _logFactory = logFactory ?? new AzureDiagnosticsTraceListenerFactory();
     _logLevel = loggerLevel ?? LoggerLevel.Info;
     _logger = _logFactory.Create(GetType(), _logLevel);
     _diagnosticsLogLevel = diagnosticsLogLevel ?? LogLevel.Information;
 }
Пример #10
0
      private static string FormatMessage(LoggerLevel loggerLevel, string message)
      {
         string messageIdentifier = String.Empty;

         switch (loggerLevel)
         {
            case LoggerLevel.Off:
               messageIdentifier = " ";
               break;
            case LoggerLevel.Error:
            case LoggerLevel.Fatal:
               messageIdentifier = "X";
               break;
            case LoggerLevel.Warn:
               messageIdentifier = "!";
               break;
            case LoggerLevel.Info:
               messageIdentifier = "-";
               break;
            case LoggerLevel.Debug:
               messageIdentifier = "+";
               break;
         }

         DateTime dateTime = DateTime.Now;
         return String.Format("[{0}-{1}] {2} {3}", dateTime.ToShortDateString(), dateTime.ToLongTimeString(), messageIdentifier, message);
      }
 // ----------------------------------------------------------------------
 protected override void Output( LoggerLevel level, object message, Exception exception )
 {
     buffer.Append( level.ToString() );
     buffer.Append( ": " );
     buffer.AppendLine( message == null ? "null" : message.ToString() );
     Output( exception );
 }
Пример #12
0
		public ConsoleLogger(LoggerLevel level, bool console = true, bool trace = false, bool debug = false) :
			base(level)
		{
			_console = console;
			_debug = debug;
			_trace = trace;
			_color = Console.BackgroundColor;
		}
Пример #13
0
 protected override void Log(LoggerLevel loggerLevel, string loggerName, string message, Exception exception)
 {
     Console.Out.WriteLine("[{0} - {3}] '{1}' {2}", loggerLevel, loggerName, message, DateTime.Now.ToLongTimeString());
     if (exception == null)
         return;
     Console.Out.WriteLine("[{0} - {5}] '{1}' {2}: {3} {4}", loggerLevel, loggerName,
         exception.GetType().FullName, exception.Message, exception.StackTrace, DateTime.Now.ToLongTimeString());
 }
Пример #14
0
        public static void LogEntry(LoggerLevel level, string message, int code)
        {
            LogEntry log = new Code.LogEntry() { Level = level, Message = message, Code = code };

            IDocumentSession conn = JournalDb.GetDBConnection();
            conn.Store(log);
            conn.SaveChanges();
        }
Пример #15
0
 public static void Initialize(ILogger newLogger, LoggerLevel logLevel)
 {
     if (logger != null)
     {
         throw new InvalidOperationException("Logger may only be initialized once");
     }
     logger = newLogger;
     maxLogLevel = logLevel;
 }
 // ----------------------------------------------------------------------
 public LoggerEvent( LoggerLevel level, string source, string context, string message, Exception caughtException )
 {
     int levelValue = (int)level;
     this.level = levelValue < 0 ? LoggerLevel.Fatal : ( levelValue > 4 ? LoggerLevel.Fatal : level );
     this.source = ArgumentCheck.NonemptyTrimmedString( source, "source" );
     this.context = context ?? string.Empty;
     this.message = message ?? string.Empty;
     this.caughtException = caughtException;
 }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WhiteLogRedirector"/> class.
        /// </summary>
        /// <param name="name">The name for the logger.</param>
        /// <param name="level">The default log level.</param>
        /// <param name="diagnostics">The object that provides the logging for the application.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="diagnostics"/> is <see langword="null" />.
        /// </exception>
        public WhiteLogRedirector(string name, LoggerLevel level, SystemDiagnostics diagnostics)
            : base(name, level)
        {
            {
                Lokad.Enforce.Argument(() => diagnostics);
            }

            m_Diagnostics = diagnostics;
        }
Пример #18
0
        public void WriteEntry(LoggerLevel level, string format, params object[] args)
        {
            var now = DateTime.Now.ToLongTimeString();

            var message = string.Format(format, args);

            textWriter.WriteLine("[{0}] {1} {2}", now, level, message);
            textWriter.Flush();
        }
		public virtual ILogger Create(Type type, LoggerLevel level)
		{
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}

			return Create(type.FullName, level);
		}
Пример #20
0
        /// <summary>
        /// Write to the log.
        /// </summary>
        /// <param name="logText">Text to log</param>
        /// <param name="loggerLevel">Optional.</param>
        public static void Write(string logText, LoggerLevel loggerLevel = LoggerLevel.Debug, string source = "")
        {
            foreach (var logger in Loggers)
            {
                if (!logger.WillHandle(loggerLevel))
                    break;

                logger.Write(logText, loggerLevel, source);
            }
        }
        public LoggersManager(ILoggerFactory fac, LoggerLevel level)
        {
            _level = level;
            _factory = fac;

            _appLogger = new Lazy<ILogger>(() => _factory.Create("Application", _level));
            _webServerLogger = new Lazy<ILogger>(() => _factory.Create("WebServer", _level));
            _dataLogger = new Lazy<ILogger>(() => _factory.Create("DAL", _level));
            _handlersLogger = new Lazy<ILogger>(() => _factory.Create("Handler", _level));
        }
Пример #22
0
        /// <summary>
        ///   A Common method to log.
        /// </summary>
        /// <param name = "loggerLevel">The level of logging</param>
        /// <param name = "loggerName">The name of the logger</param>
        /// <param name = "message">The Message</param>
        /// <param name = "exception">The Exception</param>
        protected override void Log(LoggerLevel loggerLevel, String loggerName, String message, Exception exception)
        {
            Console.Out.WriteLine("[{0}] '{1}' {2}", loggerLevel, loggerName, message);

            if (exception != null)
            {
                Console.Out.WriteLine("[{0}] '{1}' {2}: {3} {4}", loggerLevel, loggerName, exception.GetType().FullName,
                                      exception.Message, exception.StackTrace);
            }
        }
Пример #23
0
		protected override void Log(LoggerLevel loggerLevel, string loggerName, string message, Exception exception)
		{
			if (exception == null)
			{
				traceSource.TraceEvent(MapTraceEventType(loggerLevel), 0, message);
			}
			else
			{
				traceSource.TraceData(MapTraceEventType(loggerLevel), 0, message, exception);
			}
		}
Пример #24
0
        private static void RegisterComponents(LoggerLevel loggerLevel)
        {
            SetupComponentRegistrationEvent();

            RegisterLoggers(loggerLevel);

            RegisterProviders();

            RegisterAspects();

            RegisterControllers();
        }
Пример #25
0
 /// <summary>
 /// Inserts a message into the database with the given message and level of importance.
 /// </summary>
 /// <param name="message">The message for the log.</param>
 /// <param name="level">The level of the given.</param>
 /// <returns>true if the message was successfully logged.</returns>
 /// <seealso cref="LoggerLevel"/>
 public static bool LogMessage(string message, LoggerLevel level)
 {
     Console.WriteLine(DateTime.Now.ToString("HH:mm:ss tt") + " > " + System.Enum.GetName(level.GetType(), level) + ": " + message);
     try
     {
         return controller.LogMessage(message, level);
     }
     catch (Exception ex)
     {
         Console.WriteLine(DateTime.Now.ToString("HH:mm:ss tt") + " > " + System.Enum.GetName(level.GetType(), level) + ": " + ex.Message);
         return false;
     }
 }
Пример #26
0
        public Logger(string name, bool useTimeStamp, LoggerLevel loggerLevel, params ILogger[] loggerWriters)
        {
            this.Name = name ?? string.Empty;

            if (loggerLevel == 0)
            {
                loggerLevel = LoggerLevel.Info;
            }

            this.LoggerWriters = loggerWriters.Where(x => x != null).ToList();
            this.UseTimeStamp = useTimeStamp;
            this.LoggerLevel = loggerLevel;
        }
Пример #27
0
 public static void SetLoggerLevel(LoggerLevel level)
 {
     _level = level;
     lock (_thisObject)
     {
         if (_loggerDictionary.Count > 0)
         {
             foreach (var dict in _loggerDictionary)
             {
                 dict.Value.SetLoggerLevel(level);
             }
         }
     }
 }
Пример #28
0
        public static IContainer BuildContainer(CloudStorageAccount storageAccount, ILoggerFactory logFactory, LoggerLevel logLevel)
        {
            var localTempPath = AzureConfig.GetTempLocalResourcePath();
            var localSitesPath = AzureConfig.GetSitesLocalResourcePath();
            var localExecutionPath = AzureConfig.GetExecutionLocalResourcePath();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterModule(new RepositoryModule());
            containerBuilder.RegisterModule(new LoggerModule(logFactory, logLevel));
            containerBuilder.RegisterModule(new StorageFactoryModule(storageAccount));
            containerBuilder.RegisterModule(new SyncServiceModule(storageAccount, localTempPath, localSitesPath));
            containerBuilder.RegisterModule(new BackgroundWorkerModule(localSitesPath, localExecutionPath));
            containerBuilder.RegisterModule(new WebDeployServiceModule(storageAccount));

            return containerBuilder.Build();
        }
Пример #29
0
 public void Log(string strLogMessage, LoggerLevel level)
 {
     lock (this) {
         string strType = System.Configuration.ConfigurationManager.AppSettings["logType"];
         switch (strType) {
             case "eventlog":
                 EventLogEntryType et;
                 switch (level) {
                     case LoggerLevel.Error:
                         et = EventLogEntryType.Error;
                         break;
                     case LoggerLevel.Information:
                         et = EventLogEntryType.Information;
                         break;
                     case LoggerLevel.Warning:
                         et = EventLogEntryType.Warning;
                         break;
                     default:
                         et = EventLogEntryType.Information;
                         break;
                 }
                 StampEventLogEntry(strLogMessage, et);
                 break;
             case "xml":
                 StampXmlLogEntry(strLogMessage, level);
                 break;
             default:
                 string strFile = "";
                 try {
                     strFile = System.Configuration.ConfigurationManager.AppSettings["logFile"];
                 } catch (System.Configuration.SettingsPropertyNotFoundException) {
                     strFile = System.Environment.CurrentDirectory + "\\debug.log";
                 }
                 if (strFile == "") {
                     strFile = System.Environment.CurrentDirectory + "\\debug.log";
                 } else {
                     strFile = System.Environment.CurrentDirectory + "\\" + strFile;
                 }
                 StreamWriter objLogFile = File.AppendText(strFile);
                 objLogFile.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss.ffffff") + "|" + level.ToString() + "|" + strLogMessage);
                 objLogFile.Close();
                 break;
         }
     }
 }
Пример #30
0
        public SyncService(IWebSiteRepository sitesRepository, ISyncStatusRepository syncStatusRepository, CloudStorageAccount storageAccount, string localSitesPath, string localTempPath, IEnumerable<string> directoriesToExclude, IEnumerable<string> sitesToExclude, Func<bool> syncEnabled, IISManager iisManager, ILoggerFactory loggerFactory, LoggerLevel logLevel)
        {
            _sitesRepository = sitesRepository;
            _syncStatusRepository = syncStatusRepository;

            _localSitesPath = localSitesPath;
            _localTempPath = localTempPath;
            _directoriesToExclude = directoriesToExclude;
            _sitesToExclude = sitesToExclude;
            _syncEnabled = syncEnabled;
            _iisManager = iisManager;
            _entries = new Dictionary<string, FileEntry>();
            _siteDeployTimes = new Dictionary<string, DateTime>();
            _logger = loggerFactory.Create(GetType(), logLevel);

            var sitesContainerName = AzureRoleEnvironment.GetConfigurationSettingValue(Constants.WebDeployPackagesBlobContainerKey).ToLowerInvariant();
            _container = storageAccount.CreateCloudBlobClient().GetContainerReference(sitesContainerName);
            _container.CreateIfNotExist();
        }
 public ILogger Create(Type type, LoggerLevel level)
 {
     throw new NotImplementedException();
 }
Пример #32
0
 /// <summary>
 ///   Creates a new logger, getting the logger name from the specified type.
 /// </summary>
 ILogger ILoggerFactory.Create(Type type, LoggerLevel level)
 {
     return(Create(type, level));
 }
Пример #33
0
 public new IExtendedLogger Create(string name, LoggerLevel level)
 {
     return(new ExtendedConsoleLogger(name, level));
 }
Пример #34
0
        private void UpdateColors(LoggerLevel level)
        {
            ConsoleColors colors = this.colorMappingsCache[level];

            console.SetColors(colors);
        }
Пример #35
0
 /// <summary>
 ///   Implementors output the log content by implementing this method only.
 ///   Note that exception can be null
 /// </summary>
 /// <param name = "loggerLevel"></param>
 /// <param name = "loggerName"></param>
 /// <param name = "message"></param>
 /// <param name = "exception"></param>
 protected abstract void Log(LoggerLevel loggerLevel, String loggerName, String message, Exception exception);
Пример #36
0
 /// <summary>
 /// Not implemented, NLog logger levels cannot be set at runtime.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="level">The level.</param>
 /// <returns></returns>
 /// <exception cref="NotImplementedException" />
 public override framework.ILogger Create(String name, LoggerLevel level)
 {
     throw new NotImplementedException("Logger levels cannot be set at runtime. Please review your configuration file.");
 }
Пример #37
0
 private void Log(LoggerLevel loggerLevel, String message, Exception exception)
 {
     Log(loggerLevel, Name, message, exception);
 }
Пример #38
0
        }         // Log

        // ----------------------------------------------------------------------
        public void Log(LoggerLevel level, object message, Exception exception)
        {
        }         // Log
Пример #39
0
        }         // FatalFormat

        // ----------------------------------------------------------------------
        public void Log(LoggerLevel level, object message)
        {
        }         // Log
Пример #40
0
 /// <summary>
 ///   Not implemented, NLog logger levels cannot be set at runtime.
 /// </summary>
 /// <param name="name"> The name. </param>
 /// <param name="level"> The level. </param>
 /// <returns> </returns>
 /// <exception cref="NotImplementedException" />
 public override Core.Logging.ILogger Create(String name, LoggerLevel level)
 {
     throw new NotSupportedException("Logger levels cannot be set at runtime. Please review your configuration file.");
 }
Пример #41
0
 public void SetCategoryLevel(LoggerLevel level, string categoryPath)
 {
     PInvokeUtils.ThrowIfResult(NativeMethods.Logger_SetCategoryLevel(this.Interface, (uint)level, categoryPath));
 }
Пример #42
0
 public static void LogMessage(LoggerLevel level, uint messageId, string text, InspectableAdapter pParameter)
 {
     PInvokeUtils.ThrowIfResult(NativeMethods.Logger_LogMessage((uint)level, messageId, text, pParameter != null ? pParameter.Interface:IntPtr.Zero));
 }
Пример #43
0
 protected override void Log(LoggerLevel loggerLevel, string message, Exception exception)
 {
 }
Пример #44
0
 public LoggingFacility WithLevel(LoggerLevel level)
 {
     loggerLevel = level;
     return(this);
 }
Пример #45
0
 public ILogger Create(Type type, LoggerLevel level)
 {
     return(new ConsoleLogger(type.Name, level));
 }
Пример #46
0
        }         // Log

        // ----------------------------------------------------------------------
        public void LogFormat(LoggerLevel level, string format, params object[] args)
        {
        }         // LogFormat
Пример #47
0
 public ConsoleFactory(LoggerLevel level)
 {
     this.level = level;
 }
Пример #48
0
 public ILogger Create(String name, LoggerLevel level)
 {
     return(new ConsoleLogger(name, level));
 }
 public abstract ILogger Create(String name, LoggerLevel level);
Пример #50
0
 private bool CheckLoggerLevel(LoggerLevel level)
 {
     return(level <= LoggerLevel);
 }
Пример #51
0
 protected LevelFilteredLogger(String loggerName, LoggerLevel loggerLevel) : this(loggerLevel)
 {
     ChangeName(loggerName);
 }
Пример #52
0
 private void WriteOrBufferLine(LoggerLevel level, string s)
 {
     WriteOrBuffer(level, s, true);
 }
Пример #53
0
 protected LevelFilteredLogger(LoggerLevel loggerLevel)
 {
     level = loggerLevel;
 }
 public ILogger Create(string name, LoggerLevel level)
 {
     throw new NotImplementedException();
 }
Пример #55
0
        }         // LogFormat

        // ----------------------------------------------------------------------
        public void LogFormat(LoggerLevel level, IFormatProvider provider, string format, params object[] args)
        {
        }         // LogFormat
Пример #56
0
 public override ILogger Create(string name, LoggerLevel level)
 {
     return(InternalCreate(name, level));
 }
Пример #57
0
 /// <summary>
 ///   Creates a new extended logger.
 /// </summary>
 public abstract IExtendedLogger Create(string name, LoggerLevel level);
Пример #58
0
 /// <summary>
 ///   Creates a new logger.
 /// </summary>
 ILogger ILoggerFactory.Create(string name, LoggerLevel level)
 {
     return(Create(name, level));
 }
Пример #59
0
 private ILogger InternalCreate(string name, LoggerLevel level)
 {
     return(new TraceLogger(name, level));
 }
Пример #60
0
 /// <summary>
 /// Build a new trace logger based on the named TraceSource
 /// </summary>
 /// <param name="name">The name used to locate the best TraceSource. In most cases comes from the using type's fullname.</param>
 /// <param name="level">The default logging level at which this source should write messages. In almost all cases this
 /// default value will be overridden in the config file. </param>
 public TraceLogger(string name, LoggerLevel level) : base(name, level)
 {
     Initialize();
     Level = MapLoggerLevel(traceSource.Switch.Level);
 }