Ejemplo n.º 1
0
        public static LoggingConfiguration Create(string name, string filePath = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = "Default";
            }

            // Trace Listeners
            var listener = new RollingFlatFileTraceListener((filePath ?? "Logging") + "\\" + name + ".log",
                header: string.Empty, footer: string.Empty, formatter: _SimplyFormatter,
                rollFileExistsBehavior: RollFileExistsBehavior.Increment, rollInterval: RollInterval.Day, maxArchivedFiles: 30);

            // Build Configuration
            var config = new LoggingConfiguration();
            config.DefaultSource = LogLevel.Information.ToString();
            config.IsLoggingEnabled = true;
            //config.AddLogSource(Logger.InformationCategoryName, SourceLevels.All, autoFlush: true).AddAsynchronousTraceListener(listener);
            // Special Sources Configuration
            //config.SpecialSources.Unprocessed.AddTraceListener(listener);
            config.SpecialSources.Unprocessed.Level = SourceLevels.All;
            config.SpecialSources.Unprocessed.AutoFlush = true;
            var eventLogListener = CreateEventLogTraceListener();
            config.SpecialSources.LoggingErrorsAndWarnings.AddTraceListener(eventLogListener);
            config.SpecialSources.LoggingErrorsAndWarnings.Level = SourceLevels.All;
            config.SpecialSources.LoggingErrorsAndWarnings.AutoFlush = true;
            // All Event
            config.SpecialSources.AllEvents.AddAsynchronousTraceListener(listener);
            config.SpecialSources.AllEvents.Level = SourceLevels.All;
            config.SpecialSources.AllEvents.AutoFlush = true;
            return config;
        }
Ejemplo n.º 2
0
        public EnterpriseLibraryLogger(LoggingConfiguration config)
        {
            if (config == null)
                throw new ArgumentNullException("config");

            m_LogWriter = new LogWriter(config);
        }
 private static LogWriter CreateStandardOutputLogWriter()
 {
     var traceListener = new FormattedTextWriterTraceListener(
         Console.OpenStandardOutput(), new TextFormatter("{timestamp}:\t{message}\n"));
     var config = new LoggingConfiguration();
     config.AddLogSource("StandardOutput", System.Diagnostics.SourceLevels.All, true)
         .AddAsynchronousTraceListener(traceListener);
     return new LogWriter(config);
 }
Ejemplo n.º 4
0
 public MagicLogger()
 {
     var config = new LoggingConfiguration();
     var txtFormatter = new TxtFormatter(new NameValueCollection());
     config.AddLogSource("Error", SourceLevels.Error, true).AddTraceListener(new FlatFileListener("error.txt", formatter: txtFormatter));
     config.AddLogSource("Information", SourceLevels.Information, true).AddTraceListener(new FlatFileListener("information.txt", formatter: txtFormatter));
     var loggerWriter = new LogWriter(config);
     Logger.SetLogWriter(loggerWriter, false);
 }
Ejemplo n.º 5
0
        public LoggingViewModel()
        {
            var logFormatter = new TextFormatter();

            var flatFileTraceListener = new FlatFileTraceListener("log.hblog", "-------------------------",
                "-------------------------", logFormatter);

            var config = new LoggingConfiguration();
            config.AddLogSource("Hummingbird", SourceLevels.All, true).AddTraceListener(flatFileTraceListener);
            Logger = new LogWriter(config);
        }
Ejemplo n.º 6
0
		private Logger()
		{
			string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
			TextFormatter formatter = new TextFormatter();
			var databaseTraceListener =
			  new FormattedDatabaseTraceListener(new SqlDatabase(connectionString)
			  , "WriteLog", "AddCategory", formatter);

			var config = new LoggingConfiguration();
			config.AddLogSource(LogCategories.General.ToString(), SourceLevels.All, true).AddTraceListener(databaseTraceListener);
			writer = new LogWriter(config);
			writer.Write("Starting...", LogCategories.General.ToString(), 9, 0, TraceEventType.Verbose, "Log Starting");
		}
Ejemplo n.º 7
0
		static void Main(string[] args)
		{
			TextFormatter briefFormatter = new TextFormatter();

			var flatFileTraceListerner = new FlatFileTraceListener(@"C:\temp\xxx.log",
				"-------------------------------",
				"-------------------------------",
				briefFormatter);

			var config = new LoggingConfiguration();
			config.AddLogSource("my_log", System.Diagnostics.SourceLevels.All, true).AddTraceListener(flatFileTraceListerner);
			LogWriter logger = new LogWriter(config);
		}
        private static LoggingConfiguration BuildProgrammaticConfig()
        {
            var formatter = new TextFormatter();
            var flatFileTraceListener = new FlatFileTraceListener(
                "log.txt",
                "----------------------------------------",
                "----------------------------------------",
                formatter);

            var config = new LoggingConfiguration();
            config.AddLogSource("General", SourceLevels.All, true).AddTraceListener(flatFileTraceListener);
            config.IsTracingEnabled = true;
            return config;
        }
Ejemplo n.º 9
0
        private void ConfigureLogging()
        {
            // Formatter
            TextFormatter fm = new TextFormatter();
            var flatFileTraceListener = new
              FlatFileTraceListener(@"trace.log", "----------------------------------------", "----------------------------------------", fm);

            // Build Configuration
            var config = new LoggingConfiguration();
            config.AddLogSource("General", SourceLevels.All,
               true).AddTraceListener(flatFileTraceListener);
            config.IsTracingEnabled = true;
            config.SpecialSources.AllEvents.AddTraceListener(flatFileTraceListener);
            Logger.SetLogWriter(new LogWriter(config));
        }
Ejemplo n.º 10
0
            public static LogWriter ConfigureLogWriter()
            {
                //var textFileFormatter = new TextFormatter();
                var flatFileListener = new RollingFlatFileTraceListener(@"C:\Temp\EntLibLgoFile.log");
                var asynFlatFileTraceListener = new AsynchronousTraceListenerWrapper(flatFileListener, true);

                EventLog ev = new EventLog("Application", ".", "EntLibLogging");
                EventLog eventLog = new EventLog("Application");
                var eventLogListener = new EventLogTraceListener(ev);
                var asyncEventLogListener = new AsynchronousTraceListenerWrapper(eventLogListener, true);

                var loggingConfig = new LoggingConfiguration();
                loggingConfig.AddLogSource("EntLibFlatFileLogging", SourceLevels.All, false, asynFlatFileTraceListener);
                loggingConfig.AddLogSource("EntLibEventLogLogging", SourceLevels.All, false, asyncEventLogListener);
                logWriter = new LogWriter(loggingConfig);
                return logWriter;
            }
Ejemplo n.º 11
0
        static void Main()
        {
            var loggingConfig = new LoggingConfiguration();
            var customizedWriter = new LogWriter(loggingConfig);

            var logWriterFactory = new LogWriterFactory();
            var defaultWriter = logWriterFactory.Create();

            var logEntry = new LogEntry
                {
                    EventId = 100,
                    Priority = 2,
                    Message = "Informational message",
                    Categories = { "Trace", "UI Events" }
                };

            new ManagedSecurityContextInformationProvider().PopulateDictionary(logEntry.ExtendedProperties);
            new DebugInformationProvider().PopulateDictionary(logEntry.ExtendedProperties);
            new ComPlusInformationProvider().PopulateDictionary(logEntry.ExtendedProperties);
            new UnmanagedSecurityContextInformationProvider().PopulateDictionary(logEntry.ExtendedProperties);

            defaultWriter.Write(logEntry);

            var traceManager = new TraceManager(defaultWriter);
            using (traceManager.StartTrace("Trace"))
            {
                defaultWriter.Write("Operation 1");
            }

            using (traceManager.StartTrace("UI Events", Guid.NewGuid()))
            {
                defaultWriter.Write("Operation 2", "Trace");
            }

            using (traceManager.StartTrace("Trace"))
            {
                using (traceManager.StartTrace("UI Events"))
                {
                    defaultWriter.Write("Operation 3");
                }
            }
        }
Ejemplo n.º 12
0
        internal static LoggingConfiguration BuildLoggingConfig(GlobalStateModel model)
        {
            // Formatters
            //TextFormatter formatter = new TextFormatter("Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title:{title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId:{win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}");
            TextFormatter errorFormatter = new TextFormatter("{timestamp} {message}");
            TextFormatter consoleFormatter = new TextFormatter("{timestamp} {severity} : {message}");
            // Listeners
            var errorFlatFileTraceListener = new FlatFileTraceListener(Directory.GetCurrentDirectory() + "\\" + "Error.log", "----------------------------------------", "----------------------------------------", errorFormatter);
            var outputFlatFileTraceListener = new FlatFileTraceListener(Directory.GetCurrentDirectory() + "\\" + "Output.log", "----------------------------------------", "----------------------------------------", errorFormatter);
            var outputViewTraceListener = new OutputViewTraceListener(model, consoleFormatter);
            //var consoleTraceListener = new CustomTraceListener();
            // Build Configuration
            var config = new LoggingConfiguration();
            config.AddLogSource("Error", SourceLevels.All, true).AddTraceListener(errorFlatFileTraceListener);
            config.AddLogSource("Output", SourceLevels.All, true).AddTraceListener(outputViewTraceListener);
            config.LogSources["Output"].AddTraceListener(outputFlatFileTraceListener);
            config.AddLogSource("Debug", SourceLevels.All, true).AddTraceListener(outputViewTraceListener);
            config.AddLogSource("OutputToFile", SourceLevels.All, true).AddTraceListener(outputFlatFileTraceListener);

            return config;
        }
 protected void ShoutLoop()
 {
     // Configue a LogWriter to write to the Windows Event Log.
     var eventLog = new EventLog("Application", ".", "ShoutService");
     var eventLogTraceListener = new FormattedEventLogTraceListener(eventLog)
     {
         Filter = new SeverityFilter(new TraceEventType[] {
                 TraceEventType.Error, TraceEventType.Information, TraceEventType.Warning})
     };
     var config = new LoggingConfiguration();
     config.AddLogSource("All", SourceLevels.All, true)
       .AddTraceListener(eventLogTraceListener);
     // A using statement ensures the log gets flushed when this process exits.
     using (var logWriter = new LogWriter(config))
     {
         var shouter = new Shouter(logWriter);
         do
         {
             shouter.Shout(cancellationTokenSource.Token);
         } while (!cancellationTokenSource.Token.IsCancellationRequested);
     }
 }
Ejemplo n.º 14
0
        public static LoggingConfiguration BuildProgrammaticConfig()
        {
            // Formatter
            TextFormatter briefFormatter = new TextFormatter("Timestamp: {timestamp(local)}{newline}Message: {message}{newline}");

            // Trace Listener
            var flatFileTraceListener = new FlatFileTraceListener(
                @"C:\Temp\jarwin.log",
                "----------------------------------------",
                "----------------------------------------",
                briefFormatter);

            // Build Configuration
            var config = new LoggingConfiguration();

            config.AddLogSource("jarwin", SourceLevels.All, true)
                .AddTraceListener(flatFileTraceListener);

            config.IsLoggingEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["loggingEnabled"]);

            return config;
        }
        /// <summary>Builds the configuration used to log entries to the file system.</summary>
        /// <returns>A <see cref="LoggingConfiguration"/> with default settings.</returns>
        private LoggingConfiguration BuildLoggingConfiguration()
        {
            TextFormatter formatter = new TextFormatter("Timestamp: {timestamp(local)}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}ActivityId: {property(ActivityId)}{newline}Severity: {severity}{newline}Title:{title}{newline}");

            ICollection<string> categories = new List<string> { "BlockedByFilter" };

            PriorityFilter priorityFilter = new PriorityFilter("PriorityFilter", -1);
            LogEnabledFilter logEnabledFilter = new LogEnabledFilter("LogEnabled Filter", true);
            CategoryFilter categoryFilter = new CategoryFilter("CategoryFilter", categories, CategoryFilterMode.AllowAllExceptDenied);

            RollingFlatFileTraceListener rollingFileListener = new RollingFlatFileTraceListener(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"SCH\Logs\Everything.log"),
                "----------------------------------------",
                "----------------------------------------",
                formatter,
                200,
                "yyyy-MM-dd",
                RollFileExistsBehavior.Increment,
                RollInterval.None,
                5);

            RollingFlatFileTraceListener errorFileListener = new RollingFlatFileTraceListener(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"SCH\Logs\Errors.log"),
                "----------------------------------------",
                "----------------------------------------",
                formatter,
                200,
                "yyyy-MM-dd",
                RollFileExistsBehavior.Increment,
                RollInterval.None,
                2);

            // Build Configuration
            LoggingConfiguration config = new LoggingConfiguration();
            config.Filters.Add(priorityFilter);
            config.Filters.Add(logEnabledFilter);
            config.Filters.Add(categoryFilter);

            config.AddLogSource(LoggingConstants.CategoryGeneralConst, SourceLevels.All, true, rollingFileListener);
            config.AddLogSource(LoggingConstants.CategoryCompilerConst, SourceLevels.All, true, rollingFileListener);
            config.AddLogSource(LoggingConstants.CategoryErrorConst, SourceLevels.Warning, true, errorFileListener);

            return config;
        }
Ejemplo n.º 16
0
 private static void ConfigureLogger()
 {
   var configuration = new LoggingConfiguration();
   configuration.AddLogSource("default", new ConsoleTraceListener());
   configuration.DefaultSource = "default";
   var logWriter = new LogWriter(configuration);
   Logger.SetLogWriter(logWriter, false);
 }
Ejemplo n.º 17
0
 private EnterpriseLogger()
 {
     LoggingConfiguration configuration = new LoggingConfiguration();
     LogWriter writer = new LogWriter(configuration);
     Logger.SetLogWriter(writer, false);
 }
Ejemplo n.º 18
0
    private static LoggingConfiguration BuildLoggingConfig()
    {
      // Formatters
      TextFormatter formatter = new TextFormatter("Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title:{title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId:{win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}");

      // Listeners
      var flatFileTraceListener = new FlatFileTraceListener(@"C:\Temp\SalaryCalculator.log", "----------------------------------------", "----------------------------------------", formatter);
      var eventLog = new EventLog("Application", ".", "Enterprise Library Logging");
      var eventLogTraceListener = new FormattedEventLogTraceListener(eventLog);
      // Build Configuration
      var config = new LoggingConfiguration();
      config.AddLogSource("General", SourceLevels.All, true).AddTraceListener(eventLogTraceListener);
      config.LogSources["General"].AddTraceListener(flatFileTraceListener);

      // Special Sources Configuration
      config.SpecialSources.LoggingErrorsAndWarnings.AddTraceListener(eventLogTraceListener);

      return config;
    }
Ejemplo n.º 19
0
 /// <summary>
 /// Create a LogWrite that writes to the MemoryStream.
 /// </summary>
 /// <param name="memStream">Log will be written here.</param>
 /// <returns>A new LogWriter</returns>
 private static LogWriter CreateLogWriter(MemoryStream memStream)
 {
     var config = new LoggingConfiguration();
     var source = config.AddLogSource(
         "All", System.Diagnostics.SourceLevels.All, true);
     source.AddAsynchronousTraceListener(new FormattedTextWriterTraceListener(
         memStream, new TextFormatter("{message}\n")));
     return new LogWriter(config);
 }
 public EnterpriseLibraryLoggerProvider(LoggingConfiguration config)
 {
     Requires.NotNull(config, "config");
     m_Configuration = config;
 }
Ejemplo n.º 21
0
        static LoggingConfiguration BuildProgrammaticConfig()
        {
          // Formatters
          TextFormatter formatter = new TextFormatter("Timestamp: {timestamp(local)}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}ActivityId: {property(ActivityId)}{newline}Severity: {severity}{newline}Title:{title}{newline}");

          // Category Filters
          ICollection<string> categories = new List<string>();
          categories.Add("BlockedByFilter");

          // Log Filters
          var priorityFilter = new PriorityFilter("Priority Filter", 2, 99);
          var logEnabledFilter = new LogEnabledFilter("LogEnabled Filter", true);
          var categoryFilter = new CategoryFilter("Category Filter", categories, CategoryFilterMode.AllowAllExceptDenied);

          // Trace Listeners
          var flatFileTraceListener = new FlatFileTraceListener(@"C:\Temp\ConfigSampleFlatFile.log", "----------------------------------------", "----------------------------------------", formatter);

          // Build Configuration
          var config = new LoggingConfiguration();
          config.Filters.Add(priorityFilter);
          config.Filters.Add(logEnabledFilter);
          config.Filters.Add(categoryFilter);

          config.AddLogSource("General", SourceLevels.All, true, flatFileTraceListener);

          return config;
        }
Ejemplo n.º 22
0
        private LoggingConfiguration BuildProgrammaticConfig()
        {
            // Formatters
            TextFormatter briefFormatter = new TextFormatter("Timestamp: {timestamp(local)}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}ActivityId: {property(ActivityId)}{newline}Severity: {severity}{newline}Title:{title}{newline}");
            TextFormatter extendedFormatter = new TextFormatter("Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title: {title}{newline}Activity ID: {property(ActivityId)}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId:{win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}");

            // Category Filters
            ICollection<string> categories = new List<string>();
            categories.Add("BlockedByFilter");

            // Log Filters
            var priorityFilter = new PriorityFilter("Priority Filter", 2, 99);
            var logEnabledFilter = new LogEnabledFilter("LogEnabled Filter", true);
            var categoryFilter = new CategoryFilter("Category Filter", categories, CategoryFilterMode.AllowAllExceptDenied);

            // Trace Listeners
            //var causeLoggingErrorTraceListener = new FormattedDatabaseTraceListener(DatabaseFactory.CreateDatabase("DoesNotExist"), "WriteLog", "AddCategory", null);
            //var databaseTraceListener = new FormattedDatabaseTraceListener(DatabaseFactory.CreateDatabase("ExampleDatabase"), "WriteLog", "AddCategory", extendedFormatter);
            var flatFileTraceListener = new FlatFileTraceListener(@"C:\Temp\FlatFile.log", "----------------------------------------", "----------------------------------------", briefFormatter);
            var eventLog = new EventLog("Application", ".", "Enterprise Library Logging");
            var eventLogTraceListener = new FormattedEventLogTraceListener(eventLog);
            var rollingFlatFileTraceListener = new RollingFlatFileTraceListener(@"C:\Temp\RollingFlatFile.log", "----------------------------------------", "----------------------------------------", extendedFormatter, 20, "yyyy-MM-dd", RollFileExistsBehavior.Increment, RollInterval.None, 3);
            var unprocessedFlatFileTraceListener = new FlatFileTraceListener(@"C:\Temp\Unprocessed.log", "----------------------------------------", "----------------------------------------", extendedFormatter);
            var xmlTraceListener = new XmlTraceListener(@"C:\Temp\XmlLogFile.xml");
            xmlTraceListener.Filter = new EventTypeFilter(SourceLevels.Error);

            // Build Configuration
            var config = new LoggingConfiguration();
            config.Filters.Add(priorityFilter);
            config.Filters.Add(logEnabledFilter);
            config.Filters.Add(categoryFilter);

            config.AddLogSource("BlockedByFilter", SourceLevels.All, true).AddTraceListener(eventLogTraceListener);
            //config.AddLogSource("CauseLoggingError", SourceLevels.All, true).AddTraceListener(causeLoggingErrorTraceListener);
            //config.AddLogSource("Database", SourceLevels.All, true).AddTraceListener(databaseTraceListener);
            // The defaults for the asynchronous wrapper are:
            //   bufferSize: 30000
            //   disposeTimeout: infinite
            //config.AddLogSource("AsyncDatabase", SourceLevels.All, true).AddAsynchronousTraceListener(databaseTraceListener);
            config.AddLogSource("DiskFiles", SourceLevels.All, true).AddTraceListener(flatFileTraceListener);

            config.AddLogSource("General", SourceLevels.All, true).AddTraceListener(eventLogTraceListener);
            config.AddLogSource("Important", SourceLevels.All, true).AddTraceListener(eventLogTraceListener);
            config.LogSources["Important"].AddTraceListener(rollingFlatFileTraceListener);

            // Special Sources Configuration
            config.SpecialSources.Unprocessed.AddTraceListener(unprocessedFlatFileTraceListener);
            config.SpecialSources.LoggingErrorsAndWarnings.AddTraceListener(eventLogTraceListener);

            return config;
        }