/// <summary>
        /// Adds a sink that writes audit events to MariaDB/MySQL table
        /// </summary>
        /// <param name="loggerAuditConfiguration">Options for the sink</param>
        /// <param name="options">Additional options for audit sink</param>
        /// <param name="tableName">Name of the database table used for storing events</param>
        /// <param name="autoCreateTable">If true the sink will create a SQL table if it doesn't exist</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink</param>
        public static LoggerConfiguration MariaDB(
            this LoggerAuditSinkConfiguration loggerAuditConfiguration,
            string connectionString,
            IFormatProvider formatProvider = null,
            MariaDBSinkOptions options     = null,
            string tableName     = "Logs",
            bool autoCreateTable = false,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum
            )
        {
            if (loggerAuditConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerAuditConfiguration));
            }

            return(loggerAuditConfiguration.Sink(
                       new MariaDBAuditSink(
                           connectionString,
                           formatProvider,
                           options ?? new MariaDBSinkOptions(),
                           tableName,
                           autoCreateTable
                           ),
                       restrictedToMinimumLevel
                       ));
        }
        /// <summary>
        /// Adds a sink that writes log events to a table in a MSSqlServer database.
        /// </summary>
        /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
        /// <param name="connectionString">The connection string to the database where to store the events.</param>
        /// <param name="sinkOptions">Supplies additional settings for the sink</param>
        /// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
        /// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="columnOptions">An externally-modified group of column settings</param>
        /// <param name="columnOptionsSection">A config section defining various column settings</param>
        /// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MSSqlServer(
            this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
            string connectionString,
            MSSqlServerSinkOptions sinkOptions       = null,
            IConfigurationSection sinkOptionsSection = null,
            IConfiguration appConfiguration          = null,
            LogEventLevel restrictedToMinimumLevel   = LevelAlias.Minimum,
            IFormatProvider formatProvider           = null,
            ColumnOptions columnOptions = null,
            IConfigurationSection columnOptionsSection = null,
            ITextFormatter logEventFormatter           = null)
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));
            }

            ReadConfiguration(ref connectionString, ref sinkOptions, appConfiguration, ref columnOptions,
                              columnOptionsSection, sinkOptionsSection);

            IMSSqlServerAuditSinkFactory auditSinkFactory = new MSSqlServerAuditSinkFactory();
            var auditSink = auditSinkFactory.Create(connectionString, sinkOptions, formatProvider, columnOptions, logEventFormatter);

            return(loggerAuditSinkConfiguration.Sink(auditSink, restrictedToMinimumLevel));
        }
        public static LoggerConfiguration MSSqlServer(
            this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
            string connectionString,
            string tableName,
            IConfiguration appConfiguration        = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            IFormatProvider formatProvider         = null,
            bool autoCreateSqlTable     = false,
            ColumnOptions columnOptions = null,
            IConfigurationSection columnOptionsSection = null,
            string schemaName = MSSqlServerSink.DefaultSchemaName,
            ITextFormatter logEventFormatter = null)
        {
            // Do not add new parameters here. This interface is considered legacy and will be deprecated in the future.
            // For adding new input parameters use the MSSqlServerSinkOptions class and the method overload that accepts MSSqlServerSinkOptions.

            var sinkOptions = new MSSqlServerSinkOptions(tableName, null, null, autoCreateSqlTable, schemaName);

            return(loggerAuditSinkConfiguration.MSSqlServer(
                       connectionString: connectionString,
                       sinkOptions: sinkOptions,
                       sinkOptionsSection: null,
                       appConfiguration: appConfiguration,
                       restrictedToMinimumLevel: restrictedToMinimumLevel,
                       formatProvider: formatProvider,
                       columnOptions: columnOptions,
                       columnOptionsSection: columnOptionsSection,
                       logEventFormatter: logEventFormatter));
        }
예제 #4
0
        /// <summary>
        /// Audits log events to <see cref="T:ExcelDna.Logging.LogDisplay" />.
        /// </summary>
        /// <param name="sinkConfiguration">Audit Logger sink configuration.</param>
        /// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To
        /// control plain text formatting, use the overload that accepts an output template.</param>
        /// <param name="restrictedToMinimumLevel">The minimum level for
        /// events passed through the sink. Ignored when <paramref name="levelSwitch" /> is specified.</param>
        /// <param name="levelSwitch">A switch allowing the pass-through minimum level
        /// to be changed at runtime.</param>
        /// <param name="displayOrder">The order in which messages are displayed in the log viewer.
        /// The default is <see cref="F:ExcelDna.Logging.NewestLast" />.</param>
        /// <param name="clearLogOnDispose">Calls <see cref="LogDisplay.Clear()" /> when the sink is disposed.
        /// The default is <see langword="false" />.</param>
        /// <returns>Configuration object allowing method chaining.</returns>
        public static LoggerConfiguration ExcelDnaLogDisplay(this LoggerAuditSinkConfiguration sinkConfiguration,
                                                             ITextFormatter formatter, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose,
                                                             LoggingLevelSwitch levelSwitch = null, DisplayOrder displayOrder = DisplayOrder.NewestLast, bool clearLogOnDispose = false)
        {
            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            if (!Enum.IsDefined(typeof(LogEventLevel), restrictedToMinimumLevel))
            {
                throw new InvalidEnumArgumentException(nameof(restrictedToMinimumLevel), (int)restrictedToMinimumLevel,
                                                       typeof(LogEventLevel));
            }

            if (!Enum.IsDefined(typeof(DisplayOrder), displayOrder))
            {
                throw new InvalidEnumArgumentException(nameof(displayOrder), (int)displayOrder, typeof(DisplayOrder));
            }

            return(sinkConfiguration.Sink(new ExcelDnaLogDisplaySink(formatter, displayOrder, clearLogOnDispose), restrictedToMinimumLevel, levelSwitch));
        }
예제 #5
0
        /// <summary>
        /// Adds a sink that writes log events to a table in a MSSqlServer database.
        /// Create a database and execute the table creation script found here
        /// https://gist.github.com/mivano/10429656
        /// or use the autoCreateSqlTable option.
        /// </summary>
        /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
        /// <param name="connectionString">The connection string to the database where to store the events.</param>
        /// <param name="tableName">Name of the table to store the events in.</param>
        /// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
        /// <param name="columnOptions"></param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MSSqlServer(this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
                                                      string connectionString,
                                                      string tableName,
                                                      LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
                                                      IFormatProvider formatProvider         = null,
                                                      bool autoCreateSqlTable     = false,
                                                      ColumnOptions columnOptions = null,
                                                      string schemaName           = "dbo")
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException("loggerAuditSinkConfiguration");
            }

            var colOpts = columnOptions ?? new ColumnOptions();

            if (ConfigurationManager.GetSection(AppConfigSectionName) is MSSqlServerConfigurationSection serviceConfigSection)
            {
                colOpts = ApplySystemConfiguration.ConfigureColumnOptions(serviceConfigSection, colOpts);
            }

            connectionString = ApplySystemConfiguration.GetConnectionString(connectionString);

            return(loggerAuditSinkConfiguration.Sink(
                       new MSSqlServerAuditSink(
                           connectionString,
                           tableName,
                           formatProvider,
                           autoCreateSqlTable,
                           colOpts,
                           schemaName
                           ),
                       restrictedToMinimumLevel));
        }
예제 #6
0
        /// <summary>
        /// Adds a sink that writes log events to a table in a MSSqlServer database.
        /// </summary>
        /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
        /// <param name="connectionString">The connection string to the database where to store the events.</param>
        /// <param name="tableName">Name of the table to store the events in.</param>
        /// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
        /// <param name="columnOptions">An externally-modified group of column settings</param>
        /// <param name="columnOptionsSection">A config section defining various column settings</param>
        /// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MSSqlServer(
            this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
            string connectionString,
            string tableName,
            IConfiguration appConfiguration        = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            IFormatProvider formatProvider         = null,
            bool autoCreateSqlTable     = false,
            ColumnOptions columnOptions = null,
            IConfigurationSection columnOptionsSection = null,
            string schemaName = "dbo"
            )
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException("loggerAuditSinkConfiguration");
            }

            var connectionStr = ApplyMicrosoftExtensionsConfiguration.GetConnectionString(connectionString, appConfiguration);
            var colOpts       = ApplyMicrosoftExtensionsConfiguration.ConfigureColumnOptions(columnOptions, columnOptionsSection);

            return(loggerAuditSinkConfiguration.Sink(
                       new MSSqlServerAuditSink(
                           connectionString,
                           tableName,
                           formatProvider,
                           autoCreateSqlTable,
                           columnOptions,
                           schemaName
                           ),
                       restrictedToMinimumLevel));
        }
        /// <summary>
        /// A sink that puts log events into a provided Azure Event Hub.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="formatter">Formatter used to convert log events to text.</param>
        /// <param name="connectionString">The Event Hub connection string.</param>
        /// <param name="eventHubName">The Event Hub name.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration AzureEventHub(
            this LoggerAuditSinkConfiguration loggerConfiguration,
            ITextFormatter formatter,
            string connectionString,
            string eventHubName,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum
            )
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException("loggerConfiguration");
            }
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException("connectionString");
            }
            if (string.IsNullOrWhiteSpace(eventHubName))
            {
                throw new ArgumentNullException("eventHubName");
            }

            var client = new EventHubProducerClient(connectionString, eventHubName);

            return(AzureEventHub(loggerConfiguration, formatter, client, restrictedToMinimumLevel));
        }
예제 #8
0
        /// <summary>
        /// Write audit log events to the specified file.
        /// </summary>
        /// <param name="sinkConfiguration">Logger sink configuration.</param>
        /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into
        /// text for the file. If control of regular text formatting is required, use the other
        /// overload of <see cref="PersistentFile(Serilog.Configuration.LoggerAuditSinkConfiguration,string,Serilog.Events.LogEventLevel,string,System.IFormatProvider,Serilog.Core.LoggingLevelSwitch,System.Text.Encoding,Serilog.Sinks.PersistentFile.FileLifecycleHooks)"/>
        /// and specify the outputTemplate parameter instead.
        /// </param>
        /// <param name="path">Path to the file.</param>
        /// <param name="restrictedToMinimumLevel">The minimum level for
        /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
        /// <param name="levelSwitch">A switch allowing the pass-through minimum level
        /// to be changed at runtime.</param>
        /// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param>
        /// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param>
        /// <returns>Configuration object allowing method chaining.</returns>
        public static LoggerConfiguration PersistentFile(
            this LoggerAuditSinkConfiguration sinkConfiguration,
            ITextFormatter formatter,
            string path,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            LoggingLevelSwitch levelSwitch         = null,
            Encoding encoding        = null,
            FileLifecycleHooks hooks = null)
        {
            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            return(ConfigureFile(sinkConfiguration.Sink, formatter, path, restrictedToMinimumLevel, null, levelSwitch, false, true,
                                 false, null, encoding, PersistentFileRollingInterval.Infinite, false, null, hooks));
        }
        /// <summary>
        /// Adds a sink that writes log events to a table in a MSSqlServer database.
        /// Create a database and execute the table creation script found here
        /// https://gist.github.com/mivano/10429656
        /// or use the autoCreateSqlTable option.
        /// </summary>
        /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
        /// <param name="connectionString">The connection string to the database where to store the events.</param>
        /// <param name="tableName">Name of the table to store the events in.</param>
        /// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
        /// <param name="columnOptions"></param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MSSqlServer(this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
                                                      string connectionString,
                                                      string tableName,
                                                      LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
                                                      IFormatProvider formatProvider = null,
                                                      bool autoCreateSqlTable = false,
                                                      ColumnOptions columnOptions = null,
                                                      string schemaName = "dbo")
        {
            if (loggerAuditSinkConfiguration == null) throw new ArgumentNullException("loggerAuditSinkConfiguration");

            // If we have additional columns from config, load them as well
            if (ConfigurationManager.GetSection("MSSqlServerSettingsSection") is MSSqlServerConfigurationSection serviceConfigSection && serviceConfigSection.Columns.Count > 0)
            {
                if (columnOptions == null)
                {
                    columnOptions = new ColumnOptions();
                }
                GenerateDataColumnsFromConfig(serviceConfigSection, columnOptions);
            }

            connectionString = GetConnectionString(connectionString);

            return loggerAuditSinkConfiguration.Sink(
                new MSSqlServerAuditSink(
                    connectionString,
                    tableName,
                    formatProvider,
                    autoCreateSqlTable,
                    columnOptions,
                    schemaName
                    ),
                restrictedToMinimumLevel);
        }
예제 #10
0
        /// <summary>
        /// Write audit log events to the specified file.
        /// </summary>
        /// <param name="sinkConfiguration">Logger sink configuration.</param>
        /// <param name="path">Path to the file.</param>
        /// <param name="restrictedToMinimumLevel">The minimum level for
        /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
        /// <param name="levelSwitch">A switch allowing the pass-through minimum level
        /// to be changed at runtime.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="outputTemplate">A message template describing the format used to write to the sink.
        /// the default is "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}".</param>
        /// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param>
        /// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param>
        /// <returns>Configuration object allowing method chaining.</returns>
        public static LoggerConfiguration PersistentFile(
            this LoggerAuditSinkConfiguration sinkConfiguration,
            string path,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            string outputTemplate          = DefaultOutputTemplate,
            IFormatProvider formatProvider = null,
            LoggingLevelSwitch levelSwitch = null,
            Encoding encoding        = null,
            FileLifecycleHooks hooks = null)
        {
            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (outputTemplate == null)
            {
                throw new ArgumentNullException(nameof(outputTemplate));
            }

            var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);

            return(PersistentFile(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, encoding, hooks));
        }
        // Internal overload with parameters used by tests to override the config section and inject mocks
        internal static LoggerConfiguration MSSqlServerInternal(
            this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
            string connectionString,
            MSSqlServerSinkOptions sinkOptions,
            IConfigurationSection sinkOptionsSection,
            IConfiguration appConfiguration,
            LogEventLevel restrictedToMinimumLevel,
            IFormatProvider formatProvider,
            ColumnOptions columnOptions,
            IConfigurationSection columnOptionsSection,
            ITextFormatter logEventFormatter,
            IApplySystemConfiguration applySystemConfiguration,
            IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration,
            IMSSqlServerAuditSinkFactory auditSinkFactory)
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));
            }

            ReadConfiguration(ref connectionString, ref sinkOptions, sinkOptionsSection, appConfiguration,
                              ref columnOptions, columnOptionsSection, applySystemConfiguration, applyMicrosoftExtensionsConfiguration);

            var auditSink = auditSinkFactory.Create(connectionString, sinkOptions, formatProvider, columnOptions, logEventFormatter);

            return(loggerAuditSinkConfiguration.Sink(auditSink, restrictedToMinimumLevel));
        }
        /// <summary>
        /// A sink that puts log events into a provided Azure Event Hub.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="formatter">Formatter used to convert log events to text.</param>
        /// <param name="connectionString">The Event Hub connection string.</param>
        /// <param name="eventHubName">The Event Hub name.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration AzureEventHub(
            this LoggerAuditSinkConfiguration loggerConfiguration,
            ITextFormatter formatter,
            string connectionString,
            string eventHubName,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum
            )
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException("loggerConfiguration");
            }
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException("connectionString");
            }
            if (string.IsNullOrWhiteSpace(eventHubName))
            {
                throw new ArgumentNullException("eventHubName");
            }

            var connectionStringBuilder = new EventHubsConnectionStringBuilder(connectionString)
            {
                EntityPath = eventHubName
            };
            var client = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

            return(AzureEventHub(loggerConfiguration, formatter, client, restrictedToMinimumLevel));
        }
        /// <summary>
        /// A sink that puts log events into a provided Azure Event Hub.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="eventHubClient">The Event Hub to use to insert the log entries to.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="outputTemplate">A message template describing the format used to write to the sink.
        /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration AzureEventHub(
            this LoggerAuditSinkConfiguration loggerConfiguration,
            EventHubClient eventHubClient,
            string outputTemplate                  = DefaultOutputTemplate,
            IFormatProvider formatProvider         = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum
            )
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException("loggerConfiguration");
            }
            if (eventHubClient == null)
            {
                throw new ArgumentNullException("eventHubClient");
            }
            if (outputTemplate == null)
            {
                throw new ArgumentNullException("outputTemplate");
            }

            var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);

            return(AzureEventHub(loggerConfiguration, formatter, eventHubClient, restrictedToMinimumLevel));
        }
 internal static LoggerConfiguration Sink(
     LoggerAuditSinkConfiguration auditSinkConfiguration,
     ILogEventSink sink,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     LoggingLevelSwitch levelSwitch         = null)
 {
     return(auditSinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch));
 }
예제 #15
0
 public static LoggerConfiguration PersistentFile(
     this LoggerAuditSinkConfiguration sinkConfiguration,
     ITextFormatter formatter,
     string path,
     LogEventLevel restrictedToMinimumLevel,
     LoggingLevelSwitch levelSwitch)
 {
     return(PersistentFile(sinkConfiguration, formatter, path, restrictedToMinimumLevel, levelSwitch, null, null));
 }
 /// <summary>
 /// Write log events to the specified file.
 /// </summary>
 /// <param name="sinkConfiguration">Logger sink configuration.</param>
 /// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into
 /// text for the file. If control of regular text formatting is required, use the other
 /// overload of <see cref="File(LoggerAuditSinkConfiguration, string, LogEventLevel, string, IFormatProvider, LoggingLevelSwitch)"/>
 /// and specify the outputTemplate parameter instead.
 /// </param>
 /// <param name="path">Path to the file.</param>
 /// <param name="restrictedToMinimumLevel">The minimum level for
 /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
 /// <param name="levelSwitch">A switch allowing the pass-through minimum level
 /// to be changed at runtime.</param>
 /// <returns>Configuration object allowing method chaining.</returns>
 /// <remarks>The file will be written using the UTF-8 character set.</remarks>
 public static LoggerConfiguration File(
     this LoggerAuditSinkConfiguration sinkConfiguration,
     ITextFormatter formatter,
     string path,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     LoggingLevelSwitch levelSwitch         = null)
 {
     return(ConfigureFile(sinkConfiguration.Sink, formatter, path, restrictedToMinimumLevel, null, levelSwitch, false, true));
 }
 public static LoggerConfiguration DummyRollingFile(
     this LoggerAuditSinkConfiguration loggerSinkConfiguration,
     string pathFormat,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     string outputTemplate          = null,
     IFormatProvider formatProvider = null)
 {
     return(loggerSinkConfiguration.Sink(new DummyRollingFileAuditSink(), restrictedToMinimumLevel));
 }
예제 #18
0
        public static LoggerConfiguration Db(this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration, IDbSinkCore dbSinkCore, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException("loggerAuditSinkConfiguration");
            }

            return(loggerAuditSinkConfiguration.Sink(new DbAuditSink(dbSinkCore), restrictedToMinimumLevel));
        }
예제 #19
0
 public static LoggerConfiguration PersistentFile(
     this LoggerAuditSinkConfiguration sinkConfiguration,
     string path,
     LogEventLevel restrictedToMinimumLevel,
     string outputTemplate,
     IFormatProvider formatProvider,
     LoggingLevelSwitch levelSwitch)
 {
     return(PersistentFile(sinkConfiguration, path, restrictedToMinimumLevel, outputTemplate, formatProvider, levelSwitch, null, null));
 }
 /// <summary>
 /// Adds a <see cref="TestCorrelatorSink"/> to audit to.
 /// </summary>
 /// <param name="loggerAuditSinkConfiguration">The LoggerAuditSinkConfiguration to audit to.</param>
 /// <param name="restrictedToMinimumLevel">The minimum LogEventLevel for events passed to the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
 /// <param name="levelSwitch">A switch allowing the minimum LogEventLevel to be changed at runtime.</param>
 /// <returns>A modified LoggerConfiguration allowing configuration to continue.</returns>
 public static LoggerConfiguration TestCorrelator(
     this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     LoggingLevelSwitch levelSwitch         = null)
 {
     return(loggerAuditSinkConfiguration.Sink(
                new TestCorrelatorSink(),
                restrictedToMinimumLevel,
                levelSwitch));
 }
예제 #21
0
 // AuditTo
 public static LoggerConfiguration Dummy(
     this LoggerAuditSinkConfiguration loggerSinkConfiguration,
     string stringParam,
     int intParam,
     string stringParamWithDefault          = "default",
     int?nullableIntParam                   = 42,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
 {
     return(loggerSinkConfiguration.Sink(new DummyAuditSink(stringParam, intParam, stringParamWithDefault, nullableIntParam, null),
                                         restrictedToMinimumLevel));
 }
예제 #22
0
        public static LoggerConfiguration Db(this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration, Action <DbOptions> dbAction = null, ITableCreator tableCreator = null, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, IConfigurationSection columnOptionsSection = null)
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException("loggerAuditSinkConfiguration");
            }

            DbOptions opt = new DbOptions();

            dbAction?.Invoke(opt);
            opt.ColumnOptions = ApplyMicrosoftExtensionsConfiguration.ConfigureColumnOptions(opt.ColumnOptions, columnOptionsSection);
            return(loggerAuditSinkConfiguration.Sink(new DbAuditSink(opt, tableCreator ?? new DefaultTableCreator()), restrictedToMinimumLevel));
        }
        /// <summary>
        /// Adds a sink that writes log events to a table in a MSSqlServer database.
        /// </summary>
        /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
        /// <param name="connectionString">The connection string to the database where to store the events.</param>
        /// <param name="tableName">Name of the table to store the events in.</param>
        /// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
        /// <param name="columnOptions">An externally-modified group of column settings</param>
        /// <param name="columnOptionsSection">A config section defining various column settings</param>
        /// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MSSqlServer(
            this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
            string connectionString,
            string tableName,
            IConfiguration appConfiguration        = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            IFormatProvider formatProvider         = null,
            bool autoCreateSqlTable     = false,
            ColumnOptions columnOptions = null,
            IConfigurationSection columnOptionsSection = null,
            string schemaName = "dbo"
            )
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException("loggerAuditSinkConfiguration");
            }

            var colOpts = columnOptions ?? new ColumnOptions();
            var connStr = connectionString;

            if (ConfigurationManager.GetSection(AppConfigSectionName) is MSSqlServerConfigurationSection serviceConfigSection)
            {
                colOpts = ApplySystemConfiguration.ConfigureColumnOptions(serviceConfigSection, colOpts);
                connStr = ApplySystemConfiguration.GetConnectionString(connStr);

                if (appConfiguration != null || columnOptionsSection != null)
                {
                    SelfLog.WriteLine("Warning: Both System.Configuration (app.config or web.config) and Microsoft.Extensions.Configuration are being applied to the MSSQLServer sink.");
                }
            }

            if (appConfiguration != null || columnOptionsSection != null)
            {
                connStr = ApplyMicrosoftExtensionsConfiguration.GetConnectionString(connStr, appConfiguration);
                colOpts = ApplyMicrosoftExtensionsConfiguration.ConfigureColumnOptions(colOpts, columnOptionsSection);
            }

            return(loggerAuditSinkConfiguration.Sink(
                       new MSSqlServerAuditSink(
                           connStr,
                           tableName,
                           formatProvider,
                           autoCreateSqlTable,
                           colOpts,
                           schemaName
                           ),
                       restrictedToMinimumLevel));
        }
예제 #24
0
        private static RabbitMqSinkOptions Create(this LoggerAuditSinkConfiguration configuration, Action <RabbitMqSinkOptions> optionsSetup)
        {
            if (optionsSetup == null)
            {
                throw new ArgumentNullException(nameof(optionsSetup));
            }

            RabbitMqSinkOptions options = new RabbitMqSinkOptions();

            // Set confirm publish by default for Audit
            options.ConfirmPublish = true;
            options.ExchangeName   = RabbitMqSinkOptions.DefaultAuditToExchange;
            optionsSetup.Invoke(options);

            return(options);
        }
예제 #25
0
 /// <summary>
 /// Adds a sink that writes log events to a table in a MSSqlServer database.
 /// Create a database and execute the table creation script found here
 /// https://gist.github.com/mivano/10429656
 /// or use the autoCreateSqlTable option.
 /// </summary>
 /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
 /// <param name="connectionString">The connection string to the database where to store the events.</param>
 /// <param name="sinkOptions">Supplies additional settings for the sink</param>
 /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
 /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
 /// <param name="columnOptions"></param>
 /// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
 /// <returns>Logger configuration, allowing configuration to continue.</returns>
 /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
 public static LoggerConfiguration MSSqlServer(
     this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
     string connectionString,
     SinkOptions sinkOptions = null,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     IFormatProvider formatProvider         = null,
     ColumnOptions columnOptions            = null,
     ITextFormatter logEventFormatter       = null) =>
 loggerAuditSinkConfiguration.MSSqlServerInternal(
     configSectionName: AppConfigSectionName,
     connectionString: connectionString,
     sinkOptions: sinkOptions,
     restrictedToMinimumLevel: restrictedToMinimumLevel,
     formatProvider: formatProvider,
     columnOptions: columnOptions,
     logEventFormatter: logEventFormatter,
     applySystemConfiguration: new ApplySystemConfiguration(),
     auditSinkFactory: new MSSqlServerAuditSinkFactory());
예제 #26
0
        public static LoggerAuditSinkConfiguration RabbitMq(
            this LoggerAuditSinkConfiguration configuration,
            Action <RabbitMqSinkOptions> optionsSetup,
            IConnection connection,
            IBinaryFormatter binaryFormatter,
            LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose,
            LoggingLevelSwitch levelSwitch         = null,
            bool autoCloseConnection = true)
        {
            RabbitMqSinkOptions options = configuration.Create(optionsSetup);

            RabbitMqSink rabbitMqSink = new RabbitMqSink(options, connection, binaryFormatter,
                                                         autoCloseConnection);

            configuration.Sink(rabbitMqSink, restrictedToMinimumLevel, levelSwitch);

            return(configuration);
        }
        /// <summary>
        /// A sink that puts log events into a provided Azure Event Hub.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="formatter">Formatter used to convert log events to text.</param>
        /// <param name="eventHubClient">The Event Hub to use to insert the log entries to.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration AzureEventHub(
            this LoggerAuditSinkConfiguration loggerConfiguration,
            ITextFormatter formatter,
            EventHubClient eventHubClient,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException("loggerConfiguration");
            }
            if (eventHubClient == null)
            {
                throw new ArgumentNullException("eventHubClient");
            }

            var sink = new AzureEventHubSink(eventHubClient, formatter);

            return(loggerConfiguration.Sink(sink, restrictedToMinimumLevel));
        }
예제 #28
0
        public static LoggerAuditSinkConfiguration RabbitMq(
            this LoggerAuditSinkConfiguration configuration,
            Action <RabbitMqSinkOptions> optionsSetup,
            IEndpointResolver endpointResolver,
            Action <ConnectionFactory> connectionFactorySetup,
            IBinaryFormatter binaryFormatter,
            LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose,
            LoggingLevelSwitch levelSwitch         = null,
            string clientProviderName = null)
        {
            RabbitMqSinkOptions options = configuration.Create(optionsSetup);

            RabbitMqSink rabbitMqSink = new RabbitMqSink(options, endpointResolver, connectionFactorySetup, binaryFormatter,
                                                         clientProviderName);

            configuration.Sink(rabbitMqSink, restrictedToMinimumLevel, levelSwitch);

            return(configuration);
        }
예제 #29
0
        public static LoggerAuditSinkConfiguration RabbitMq(
            this LoggerAuditSinkConfiguration configuration,
            Action <RabbitMqSinkOptions> optionsSetup,
            IConnection connection,
            LogEventJsonConverterOptions jsonConverterOptions = null,
            LogEventLevel restrictedToMinimumLevel            = LogEventLevel.Verbose,
            LoggingLevelSwitch levelSwitch = null,
            bool autoCloseConnection       = true)
        {
            RabbitMqSinkOptions options = configuration.Create(optionsSetup);

            RabbitMqSink rabbitMqSink = new RabbitMqSink(options, connection,
                                                         new JsonToUtf8BytesFormatter(jsonConverterOptions ?? new LogEventJsonConverterOptions()),
                                                         autoCloseConnection);

            configuration.Sink(rabbitMqSink, restrictedToMinimumLevel, levelSwitch);

            return(configuration);
        }
예제 #30
0
        public static LoggerAuditSinkConfiguration RabbitMq(
            this LoggerAuditSinkConfiguration configuration,
            Action <RabbitMqSinkOptions> optionsSetup,
            IList <AmqpTcpEndpoint> endpoints,
            Action <ConnectionFactory> connectionFactorySetup,
            LogEventJsonConverterOptions jsonConverterOptions = null,
            LogEventLevel restrictedToMinimumLevel            = LogEventLevel.Verbose,
            LoggingLevelSwitch levelSwitch = null,
            string clientProviderName      = null)
        {
            RabbitMqSinkOptions options = configuration.Create(optionsSetup);

            RabbitMqSink rabbitMqSink = new RabbitMqSink(options, endpoints, connectionFactorySetup,
                                                         new JsonToUtf8BytesFormatter(jsonConverterOptions ?? new LogEventJsonConverterOptions()),
                                                         clientProviderName);

            configuration.Sink(rabbitMqSink, restrictedToMinimumLevel, levelSwitch);

            return(configuration);
        }