示例#1
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="stream">A <see cref="System.IO.Stream"/> derived class to output log events to.</param>
        /// <param name="encoding">A <see cref="System.Text.Encoding"/> instance used to output the log event data to the stream.</param>
        /// <param name="eventFormatter">A <see cref="ILogEventFormatter"/> instance used to format the event before writing to the stream. If null then <see cref="SimpleLogEventFormatter.DefaultInstance"/> is used.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="stream"/> is null.</exception>
        public StreamLogWriter(System.IO.Stream stream, System.Text.Encoding encoding, ILogEventFormatter eventFormatter)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            _Writer            = new System.IO.StreamWriter(stream, encoding ?? System.Text.UTF8Encoding.UTF8);
            _LogEventFormatter = eventFormatter ?? SimpleLogEventFormatter.DefaultInstance;
        }
 public ConsoleLogger(ILogEventFormatter <T, string> formatter)
 {
     _formatter = formatter;
 }
示例#3
0
 public ColoredConsoleLogger(ILogEventFormatter <LogEvent, string> formatter) : base(formatter)
 {
 }
示例#4
0
 public DebugLogWriter(ILogEventFormatter eventFormatter, ILogEventFilter filter) : base(filter)
 {
     _LogEventFormatter = eventFormatter ?? SimpleLogEventFormatter.DefaultInstance;
 }
示例#5
0
 /// <summary>
 /// Full constructor.
 /// </summary>
 /// <param name="eventFormatter">A <see cref="ILogEventFormatter"/> implementation used to format the event log entries to text for outputting.</param>
 public TraceLogWriter(ILogEventFormatter eventFormatter)
 {
     _LogEventFormatter = eventFormatter ?? SimpleLogEventFormatter.DefaultInstance;
 }
        /// <summary>
        /// Creates a new event source and log if required and configures the writer to output events there.
        /// </summary>
        /// <remarks>
        /// <para>Warning: It's often a better idea to pre-create the event log and use the <see cref="WindowsEventLogWriter(System.Diagnostics.EventLog, ILogEventFormatter)"/> constructor to avoid issues.
        /// Creating new event sources and logs requires administrative priviledges on Windows.
        /// Newly created event logs are not always available immediately, and output to them can either fail or be redirected to the application event log (often until a reboot).
        /// </para>
        /// </remarks>
        /// <param name="eventLogName">The name of the Window Event log to write to.</param>
        /// <param name="eventSourceName">The name of the Windows Event Source associated with events output from this writer.</param>
        /// <param name="eventLogMachineName">The name of the machine hosting the event log to output to. If blank or null the local machine is used.</param>
        /// <param name="createEventLog">If true the event log will be created if it doesn't exist, otherwise an exception will be thrown.</param>
        /// <param name="overflowAction">Specifies the overflow policy for the Windows Event Log policy if the event log is to be created.</param>
        /// <param name="retentionDays">Specifies the number of days to keep events for before overwriting them, used if the event log is to be created.</param>
        /// <param name="eventFormatter">A <see cref="ILogEventFormatter"/> implementation used to format the event log entries to text for outputting.</param>
        public WindowsEventLogWriter(string eventLogName, string eventSourceName, string eventLogMachineName, bool createEventLog, System.Diagnostics.OverflowAction overflowAction, int retentionDays, ILogEventFormatter eventFormatter)
        {
            eventLogName = eventLogName ?? "Application";
            if (String.IsNullOrWhiteSpace(eventLogName))
            {
                throw new ArgumentException(nameof(eventLogName) + " cannot be empty or whitespace.", nameof(eventLogName));
            }
            if (eventSourceName == null)
            {
                throw new ArgumentNullException(nameof(eventSourceName));
            }
            if (String.IsNullOrWhiteSpace(eventSourceName))
            {
                throw new ArgumentException(nameof(eventSourceName) + " cannot be empty or whitespace.", nameof(eventSourceName));
            }

            _EventFormatter = eventFormatter;
            eventSourceName = SafeEventSourceName(eventSourceName);

            if (createEventLog)
            {
                if (String.IsNullOrWhiteSpace(eventLogMachineName))
                {
                    eventLogMachineName = ".";
                }
                if (!System.Diagnostics.EventLog.SourceExists(eventSourceName, eventLogMachineName))
                {
                    var creationData = new System.Diagnostics.EventSourceCreationData(eventSourceName, eventLogName);
                    creationData.MachineName = eventLogMachineName;
                    System.Diagnostics.EventLog.CreateEventSource(creationData);

                    var log = new System.Diagnostics.EventLog(eventLogName, eventLogMachineName);
                    log.ModifyOverflowPolicy(overflowAction, retentionDays);
                }
            }

            _Log = new System.Diagnostics.EventLog(eventLogName, eventLogMachineName, eventSourceName);
        }
示例#7
0
 public DebugLogWriter(ILogEventFormatter eventFormatter) : this(eventFormatter, null)
 {
 }
示例#8
0
 public ConsoleLogWriter(ILogEventFormatter eventFormatter) : this(eventFormatter, null)
 {
 }
示例#9
0
 public ConsoleLogWriter(ILogEventFormatter eventFormatter, ILogEventFilter filter) : base(filter)
 {
     _LogEventFormatter = eventFormatter;
 }
示例#10
0
 public TraceLogWriter(ILogEventFormatter eventFormatter) : this(eventFormatter, null)
 {
 }
示例#11
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="connectionString">The connection string to the database.</param>
        /// <param name="tableName">Then name of the table to log to.</param>
        /// <param name="columnMappings">An <see cref="IDictionary{TKey, TValue}"/> implementation where each key is a property name from the <see cref="LogEvent"/> class or it's <see cref="LogEvent.Properties"/> collection, and the value is the name of the column in the destination table. If null, only columns whose names match exactly to <see cref="LogEvent"/> properties or keys in the <see cref="LogEvent.Properties"/> dictionary will be written to the table.</param>
        /// <param name="logEventFormatter">A <see cref="ILogEventFormatter"/> immplementation to use when serialising an entire <see cref="LogEvent"/> instance into the "FullDetails" column. If none is provided <see cref="Formatters.JsonLogEventFormatter.DefaultInstance"/> is used.</param>
        /// <param name="truncateTextFields">If true, text values larger than the destination database column will be truncated before insert. This avoids sql errors and logs at least part of the message, but for over sized content results in truncated values being saved.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="connectionString"/> or <paramref name="tableName"/> are null.</exception>
        /// <exception cref="System.ArgumentException">Thrown if <paramref name="connectionString"/> or <paramref name="tableName"/> are empty or only contain whitespace.</exception>
        /// <remarks>
        /// <para>You can use "FullDetails" as a source column name to have the entire log event serialised into a single column. You can also use "SeverityLevel" to have the severity written as an integer rather than a string.</para>
        /// </remarks>
        public SqlServerLogWriter(string connectionString, string tableName, IDictionary <string, string> columnMappings, ILogEventFormatter logEventFormatter, bool truncateTextFields)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }
            if (String.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.PropertyCannotBeEmptyOrWhitespace, nameof(connectionString)));
            }
            if (tableName == null)
            {
                throw new ArgumentNullException(nameof(tableName));
            }
            if (String.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.PropertyCannotBeEmptyOrWhitespace, nameof(tableName)));
            }

            _ConnectionString   = connectionString;
            _TableName          = tableName;
            _ColumnMappings     = columnMappings;
            _LogEventFormatter  = logEventFormatter;
            _TruncateTextFields = truncateTextFields;
        }
 public FileLogger(IFileSystem fileSystem, ILogEventFormatter <T, string> formatter, Func <string> pathFactory)
 {
     _formatter   = formatter;
     _fileSystem  = fileSystem;
     _pathFactory = pathFactory;
 }
 public MarketTaxChangeLogger(Market market)
 {
     _baseEid   = market.GetDockingBase().Eid;
     _formatter = new LogEventFormatter(market);
 }
示例#14
0
 /// <summary>
 /// Partial constructor.
 /// </summary>
 /// <remarks><para>Instances created using this constructor have compression enabled.</para></remarks>
 /// <param name="connectionString">A connection string granting write access to the Azure event hub events are to be forwarded to.</param>
 /// <param name="formatter">An <see cref="ILogEventFormatter"/> implementation used to format events before sending to Azure. If null then <see cref="Formatters.JsonLogEventFormatter.DefaultInstance"/> is used.</param>
 /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="connectionString"/> is null.</exception>
 /// <exception cref="System.ArgumentException">Thrown if <paramref name="connectionString"/> is empty or contains only whitespace.</exception>
 public AzureEventHubLogWriter(string connectionString, ILogEventFormatter formatter) : this(connectionString, formatter, false)
 {
 }