/// <summary> /// Initializes a new instance of the <see cref="RollingFlatFileTraceListener"/> class. /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="header">The header to add before logging an entry.</param> /// <param name="footer">The footer to add after logging an entry.</param> /// <param name="formatter">The formatter.</param> /// <param name="rollSizeKB">The maxium file size (KB) before rolling.</param> /// <param name="timeStampPattern">The date format that will be appended to the new roll file.</param> /// <param name="rollFileExistsBehavior">Expected behavior that will be used when the roll file has to be created.</param> /// <param name="rollInterval">The time interval that makes the file rolles.</param> /// <param name="maxArchivedFiles">The maximum number of archived files to keep.</param> public RollingFlatFileTraceListener(string fileName, string header = DefaultSeparator, string footer = DefaultSeparator, ILogFormatter formatter = null, int rollSizeKB = 0, string timeStampPattern = "yyyy-MM-dd", RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Overwrite, RollInterval rollInterval = RollInterval.None, int maxArchivedFiles = 0) : base(fileName, header, footer, formatter) { Guard.ArgumentNotNullOrEmpty(fileName, "fileName"); this.rollSizeInBytes = rollSizeKB * 1024; this.timeStampPattern = timeStampPattern; this.rollFileExistsBehavior = rollFileExistsBehavior; this.rollInterval = rollInterval; this.maxArchivedFiles = maxArchivedFiles; this.rollingHelper = new StreamWriterRollingHelper(this); if (rollInterval == RollInterval.Midnight) { var now = this.rollingHelper.DateTimeProvider.CurrentDateTime; var midnight = now.AddDays(1).Date; this.timer = new Timer((o) => this.rollingHelper.RollIfNecessary(), null, midnight.Subtract(now), TimeSpan.FromDays(1)); } }
/// <summary> /// This constructor is initializing the text template for the logging file /// </summary> public CustomLogger() { formatter = new TextFormatter() { Template = "Timestamp: {newline}{newline}{timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}Title:{title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline})}", }; }
/// <summary> /// Initializes a new instance of <see cref="MsmqTraceListener"/>. /// </summary> /// <param name="name">The name of the new instance.</param> /// <param name="queuePath">The path to the queue to deliver to.</param> /// <param name="formatter">The formatter to use.</param> /// <param name="messagePriority">The priority for the messages to send.</param> /// <param name="recoverable">The recoverable flag for the messages to send.</param> /// <param name="timeToReachQueue">The timeToReachQueue for the messages to send.</param> /// <param name="timeToBeReceived">The timeToBeReceived for the messages to send.</param> /// <param name="useAuthentication">The useAuthentication flag for the messages to send.</param> /// <param name="useDeadLetterQueue">The useDeadLetterQueue flag for the messages to send.</param> /// <param name="useEncryption">The useEncryption flag for the messages to send.</param> /// <param name="transactionType">The <see cref="MessageQueueTransactionType"/> for the message to send.</param> /// <param name="msmqInterfaceFactory">The factory to create the msmq interfaces.</param> public MsmqTraceListener(string name, string queuePath, ILogFormatter formatter, MessagePriority messagePriority, bool recoverable, TimeSpan timeToReachQueue, TimeSpan timeToBeReceived, bool useAuthentication, bool useDeadLetterQueue, bool useEncryption, MessageQueueTransactionType transactionType, IMsmqSendInterfaceFactory msmqInterfaceFactory) : base(formatter) { this.queuePath = queuePath; this.messagePriority = messagePriority; this.recoverable = recoverable; this.timeToReachQueue = timeToReachQueue; this.timeToBeReceived = timeToBeReceived; this.useAuthentication = useAuthentication; this.useDeadLetterQueue = useDeadLetterQueue; this.useEncryption = useEncryption; this.transactionType = transactionType; this.msmqInterfaceFactory = msmqInterfaceFactory; }
/// <summary> /// Initializes a <see cref="EmailMessage"/> with the raw data to create and email, a message, and the formatter /// </summary> /// <param name="toAddress">A semicolon delimited string the represents to whom the email should be sent.</param> /// <param name="fromAddress">Represents from whom the email is sent.</param> /// <param name="subjectLineStarter">Starting text for the subject line.</param> /// <param name="subjectLineEnder">Ending text for the subject line.</param> /// <param name="smtpServer">The name of the SMTP server.</param> /// <param name="smtpPort">The port on the SMTP server to use for sending the email.</param> /// <param name="message">Represents the message to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> public EmailMessage(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, string message, ILogFormatter formatter) { this.configurationData = new EmailTraceListenerData(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, string.Empty); this.logEntry = new LogEntry(); logEntry.Message = message; this.formatter = formatter; }
public EmailLogProvider( DeliveryMethod deliveryMethod = null, ILogFormatter logFormatter = null) : base(logFormatter ?? DefaultLogFormatter) { _deliveryMethod = deliveryMethod ?? DefaultDeliveryMethod; }
public WaveDrawer(string logPath, Size chartSize, Size chartGridSize, ILogFormatter logFormatter) { this.logPath = logPath; this.chartSize = chartSize; this.logFormatter = logFormatter; this.chartGridSize = chartGridSize; }
public static void SetLogFormatter(LogEntry logEntry, ILogFormatter logFormatter) { if (logEntry != null) { _logFormatter = logFormatter; } }
public static void AddLogWriter(ILogWriter logWriter, ILogFormatter logFormatter) { logWriters.Add(new LogWriterInfo() { logWriter = logWriter, logFormatter = logFormatter }); }
public DefaultOutputHandler(ILogFilters filters, ILogFormatter formatter) { if (filters == null) throw new ArgumentNullException("filters", "A valid set of log filters is required for proper operation."); this.Filters = filters; this.Formatter = formatter; }
/// <summary> /// Initializes a new instance of <see cref="FormattedDatabaseTraceListener"/>. /// </summary> /// <param name="database">The database for writing the log.</param> /// <param name="writeLogStoredProcName">The stored procedure name for writing the log.</param> /// <param name="addCategoryStoredProcName">The stored procedure name for adding a category for this log.</param> /// <param name="formatter">The formatter.</param> public FormattedDatabaseTraceListener(Data.Database database, string writeLogStoredProcName, string addCategoryStoredProcName, ILogFormatter formatter ) : base(formatter) { this.writeLogStoredProcName = writeLogStoredProcName; this.addCategoryStoredProcName = addCategoryStoredProcName; this.database = database; }
public CsvFileOutputHandler(ILogFilters filters, ILogFormatter formatter, String filePath) { if (filters == null) throw new ArgumentNullException("filters", "A valid set of log filters is required for proper operation."); this.Filters = filters; this.Formatter = formatter; this.FilePath = filePath; }
public TestCommonLoggingEntlibTraceListener(CommonLoggingEntlibTraceListenerData data, ILogFormatter logFormatter) : base(data, logFormatter) { if (Instance != null) { throw new NotSupportedException(this.GetType().FullName + " supports only one instance"); } Instance = this; }
public CachedEmailTraceListener(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, ILogFormatter formatter, EmailAuthenticationMode authenticationMode, string userName, string password, bool useSSL, double emailCacheDuration) : base(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, formatter, authenticationMode, userName, password, useSSL) { this.emailCacheDuration = emailCacheDuration; if (emailCacheDuration > 0) { // Email cache duration is in hours this.cacheItemPolicyFactory = new AbsoluteCacheItemPolicyFactory(Convert.ToInt32(emailCacheDuration * 3600)); } }
/// <summary> /// Initializes a new instance of <see cref="MsmqTraceListener"/>. /// </summary> /// <param name="name">The name of the new instance.</param> /// <param name="queuePath">The path to the queue to deliver to.</param> /// <param name="formater">The formatter to use.</param> /// <param name="messagePriority">The priority for the messages to send.</param> /// <param name="recoverable">The recoverable flag for the messages to send.</param> /// <param name="timeToReachQueue">The timeToReachQueue for the messages to send.</param> /// <param name="timeToBeReceived">The timeToBeReceived for the messages to send.</param> /// <param name="useAuthentication">The useAuthentication flag for the messages to send.</param> /// <param name="useDeadLetterQueue">The useDeadLetterQueue flag for the messages to send.</param> /// <param name="useEncryption">The useEncryption flag for the messages to send.</param> /// <param name="transactionType">The <see cref="MessageQueueTransactionType"/> for the message to send.</param> public MsmqTraceListener(string name, string queuePath, ILogFormatter formater, MessagePriority messagePriority, bool recoverable, TimeSpan timeToReachQueue, TimeSpan timeToBeReceived, bool useAuthentication, bool useDeadLetterQueue, bool useEncryption, MessageQueueTransactionType transactionType) : this(name, queuePath, formater, messagePriority, recoverable, timeToReachQueue, timeToBeReceived, useAuthentication, useDeadLetterQueue, useEncryption, transactionType, new MsmqSendInterfaceFactory()) { }
public TextWriterOutputHandler(TextWriter writer, ILogFilters filters, ILogFormatter formatter) { if (writer == null) throw new ArgumentNullException("writer", "A valid stream writer is required for proper operation."); if (filters == null) throw new ArgumentNullException("filters", "A valid set of log filters is required for proper operation."); this.Filters = filters; this.Formatter = formatter; this.Writer = writer; }
public void CleanupTest() { this._mockLogFormatter = null; this._mockLogger = null; if (this._targetListener != null) { this._targetListener.Dispose(); this._targetListener = null; } }
/// <summary> /// Initializes a new instance of <see cref="MonitoringDatabaseTraceListener"/>. /// </summary> /// <param name="database">The database for writing the log.</param> /// <param name="formatter">The formatter.</param> /// <param name="applicationName">Name of the application.</param> /// <param name="connectionStringName">Name of the connection string.</param> public MonitoringDatabaseTraceListener(Database database, ILogFormatter formatter, string applicationName, string connectionStringName) : base(formatter) { _database = database; if (string.IsNullOrEmpty(applicationName)) { throw new ArgumentNullException("applicationName"); } _applicationName = applicationName; _connectionStringName = connectionStringName; }
public FlatFileListener(string fileName, string header = "----------------------------------", string footer = "----------------------------------", ILogFormatter formatter = null, int rollSizeKb = 20000, string timeStampPattern = "yyyy-MM-dd hh:mm:ss", RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Increment, RollInterval rollInterval = RollInterval.Day, int maxArchivedFiles = 0) : base(Path.Combine(ResolveLogPath(), fileName), header, footer, formatter, rollSizeKb, timeStampPattern, rollFileExistsBehavior, rollInterval, maxArchivedFiles) { }
public string ToString(ILogFormatter formatter) { if (formatter == null) return ToString(); try { return formatter.Format(this); } catch { return ToString(); } }
public LogglyTraceListener(string name, ILogFormatter formatter, string logglyInputKey) { if (string.IsNullOrEmpty(logglyInputKey)) { throw new ConfigurationSourceErrorsException("Invalid values in LogglyTraceListener configuration."); } else { this.Logger = new Loggly.Logger(logglyInputKey); } this.Formatter = formatter; this.Name = name; }
/// <summary> /// Initializes a <see cref="EmailMessage"/> with the raw data to create and email, the logentry, and the formatter /// </summary> /// <param name="toAddress">A semicolon delimited string the represents to whom the email should be sent.</param> /// <param name="fromAddress">Represents from whom the email is sent.</param> /// <param name="subjectLineStarter">Starting text for the subject line.</param> /// <param name="subjectLineEnder">Ending text for the subject line.</param> /// <param name="smtpServer">The name of the SMTP server.</param> /// <param name="smtpPort">The port on the SMTP server to use for sending the email.</param> /// <param name="logEntry">The LogEntry <see cref="LogEntry"/> to send via email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> /// <param name="authenticationMode">Authenticate mode to use when connecting to SMTP server.</param> /// <param name="userName">User name to send to SMTP server if using username/password authentication.</param> /// <param name="password">Password to send to SMTP server if using username/password authentication.</param> /// <param name="useSSL">Use SSL to connect to STMP server - if true, yes, if false, no.</param> public EmailMessage(string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, LogEntry logEntry, ILogFormatter formatter, EmailAuthenticationMode authenticationMode, string userName, string password, bool useSSL) { this.configurationData = new EmailTraceListenerData(toAddress, fromAddress, subjectLineStarter, subjectLineEnder, smtpServer, smtpPort, string.Empty) { AuthenticationMode = authenticationMode, UserName = userName, Password = password, UseSSL = useSSL }; this.logEntry = logEntry; this.formatter = formatter; }
/// <summary> /// Initializes a new instance of <see cref="MsmqTraceListener"/>. /// </summary> /// <param name="name">The name of the new instance.</param> /// <param name="queuePath">The path to the queue to deliver to.</param> /// <param name="formatter">The formatter to use.</param> public MsmqTraceListener(string name, string queuePath, ILogFormatter formatter) : this(name, queuePath, formatter, MsmqTraceListenerData.DefaultPriority, MsmqTraceListenerData.DefaultRecoverable, MsmqTraceListenerData.DefaultTimeToReachQueue, MsmqTraceListenerData.DefaultTimeToBeReceived, MsmqTraceListenerData.DefaultUseAuthentication, MsmqTraceListenerData.DefaultUseDeadLetter, MsmqTraceListenerData.DefaultUseEncryption, MsmqTraceListenerData.DefaultTransactionType) { }
/// <summary> /// Initializes a new instance of <see cref="EmailTraceListener"/> with a toaddress, fromaddress, /// subjectlinestarter, subjectlinender, smtpserver, smtpport, and a formatter /// a <see cref="ILogFormatter"/>. /// </summary> /// <param name="toAddress">A semicolon delimited string the represents to whom the email should be sent.</param> /// <param name="fromAddress">Represents from whom the email is sent.</param> /// <param name="subjectLineStarter">Starting text for the subject line.</param> /// <param name="subjectLineEnder">Ending text for the subject line.</param> /// <param name="smtpServer">The name of the SMTP server.</param> /// <param name="smtpPort">The port on the SMTP server to use for sending the email.</param> /// <param name="formatter">The Formatter <see cref="ILogFormatter"/> which determines how the /// email message should be formatted</param> public EmailTraceListener( string toAddress, string fromAddress, string subjectLineStarter, string subjectLineEnder, string smtpServer, int smtpPort, ILogFormatter formatter) : base(formatter) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.subjectLineStarter = subjectLineStarter; this.subjectLineEnder = subjectLineEnder; this.smtpServer = smtpServer; this.smtpPort = smtpPort; }
/// <summary> /// Initializes a new instance of <see cref="RollingFlatFileTraceListener"/> /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="header">The header to add before logging an entry.</param> /// <param name="footer">The footer to add after logging an entry.</param> /// <param name="formatter">The formatter.</param> /// <param name="rollSizeKB">The maxium file size (KB) before rolling.</param> /// <param name="timeStampPattern">The date format that will be appended to the new roll file.</param> /// <param name="rollFileExistsBehavior">Expected behavior that will be used when the rool file has to be created.</param> /// <param name="rollInterval">The time interval that makes the file rolles.</param> public RollingFlatFileTraceListener(string fileName, string header, string footer, ILogFormatter formatter, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval) : base(fileName, header, footer, formatter) { this.rollSizeInBytes = rollSizeKB * 1024; this.timeStampPattern = timeStampPattern; this.rollFileExistsBehavior = rollFileExistsBehavior; this.rollInterval = rollInterval; this.rollingHelper = new StreamWriterRollingHelper(this); }
public FileLogProvider( string file = null, ILogFormatter logFormatter = null, IAsyncWaitHandle waitHandle = null) : base(logFormatter ?? DefaultLogFormatter) { _file = file ?? _defaultFile; _waitHandle = waitHandle ?? new SemaphoreSlimAsyncWaitHandle(); _wasWaitHandleProvided = waitHandle != null; var dir = Path.GetDirectoryName(_file); if (dir != null && !Directory.Exists(dir)) { Directory.CreateDirectory(dir); } }
static XLogger() { // initialize log targets ... if ((Type & LogType.File) == LogType.File) LogMessage += (new FileLog()).Log; if ((Type & LogType.Console) == LogType.Console) LogMessage += (new ConsoleLog()).Log; if ((Type & LogType.EventLog) == LogType.EventLog) LogMessage += (new EventLog()).Log; // initialize formatter switch (Format) { case LogFormat.Text: _Formatter = new TextFormatter(); break; case LogFormat.Xml: _Formatter = new XmlFormatter(); break; } }
/// <summary> /// Initializes a new instance of <see cref="RollingFlatFileTraceListener"/> /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="header">The header to add before logging an entry.</param> /// <param name="footer">The footer to add after logging an entry.</param> /// <param name="formatter">The formatter.</param> /// <param name="rollSizeKB">The maxium file size (KB) before rolling.</param> /// <param name="timeStampPattern">The date format that will be appended to the new roll file.</param> /// <param name="rollFileExistsBehavior">Expected behavior that will be used when the roll file has to be created.</param> /// <param name="rollInterval">The time interval that makes the file rolles.</param> public RollingFlatFileTraceListener( string fileName, string header, string footer, ILogFormatter formatter, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval) : this(fileName, header, footer, formatter, rollSizeKB, timeStampPattern, rollFileExistsBehavior, rollInterval, 0) { }
public static void InitializeLogManager() { if (formatter == null) { formatter = new TextFormatter() { Template = " ------------------------------------------------------{newline}Timestamp:{timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}Title:{title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}-----------------------------------------)}", }; } if (flatFileTraceListener == null) { flatFileTraceListener = new FlatFileTraceListener(formatter) { }; } if (logSource == null) { logSource = new LogSource("Logging", new List<TraceListener>() { flatFileTraceListener }, SourceLevels.Information); } }
public File(string path, ILogFormatter<string> logFormatter = null, long maximumSize = 0) : base(logFormatter) { var rotating = maximumSize != 0; if (rotating && !ReFormatParameter.IsMatch(path)) { throw new ArgumentException( "The rotating option was specified, but the Path " + "parameter does not have a format parameter", "path" ); } Encoding = DefaultEncoding; Path = path; Rotating = rotating; MaximumLength = maximumSize; Running = false; _runLock = new object(); _runningLogs = 0; // Break the path up into directory and file name Directory = System.IO.Path.GetDirectoryName(Path); Name = System.IO.Path.GetFileName(Path); if (Directory == null || Name == null) { throw new ArgumentException( "Path could not be broken up into " + "directory and file", "path" ); } if (rotating && !ReFormatParameter.IsMatch(Name)) { throw new ArgumentException( "The format parameter must be in the filename " + "portion of the path", "path" ); } }
public WaveLogger(string logPath, ILogFormatter logFormatter) { if (string.IsNullOrEmpty(logPath)) logPath = System.Windows.Forms.Application.StartupPath; if (!Directory.Exists(logPath)) Directory.CreateDirectory(logPath); logPath = string.Concat(logPath, Path.DirectorySeparatorChar, System.DateTime.Now.ToString(logFormatter.LogDateTimeFormat), '-', (new Random()).Next(0, 100)); if (File.Exists(logPath)) File.Delete(logPath); this.logWriter = new StreamWriter(new FileStream(logPath, FileMode.Create, FileAccess.Write)); this.logFormatter = logFormatter; this.logPath = logPath; }
public FileLogAppender(string logFileDir, ILogFormatter formatter) : base(NAME, formatter) { outputDir = logFileDir; }
/// <summary> /// Initializes a new instance of <see cref="FlatFileTraceListener"/> with a file name, a header, a footer and /// a <see cref="ILogFormatter"/>. /// </summary> /// <param name="fileName">The file stream.</param> /// <param name="header">The header.</param> /// <param name="footer">The footer.</param> /// <param name="formatter">The formatter.</param> public FlatFileTraceListener(string fileName, string header = null, string footer = null, ILogFormatter formatter = null) : base(EnvironmentHelper.ReplaceEnvironmentVariables(fileName), formatter) { this.header = header ?? string.Empty; this.footer = footer ?? string.Empty; }
/// <summary> /// Initializes a new named instance of <see cref="FlatFileTraceListener"/> with a <see cref="FileStream"/> and /// a <see cref="ILogFormatter"/>. /// </summary> /// <param name="stream">The file stream.</param> /// <param name="name">The name.</param> /// <param name="formatter">The formatter.</param> public FlatFileTraceListener(FileStream stream, string name = null, ILogFormatter formatter = null) : base(stream, name, formatter) { }
/// <summary> /// Initializes a new named instance of <see cref="FlatFileTraceListener"/> with a <see cref="StreamWriter"/> and /// a <see cref="ILogFormatter"/>. /// </summary> /// <param name="writer">The stream writer.</param> /// <param name="name">The name.</param> /// <param name="formatter">The formatter.</param> public FlatFileTraceListener(StreamWriter writer, string name = null, ILogFormatter formatter = null) : base(writer, name, formatter) { }
public FormattedTraceListenerBase(ILogFormatter formatter) { this.Formatter = formatter; instrumentationProvider = new LoggingInstrumentationProvider(); }