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); }
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; }
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); }
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); }
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; }
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"); }
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; }
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)); }
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); } }
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; }
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); }
/// <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); }
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; }
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; }
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; }
/// <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; }