[英]serilog-sinks-mssqlserver: Exclude column in xml Config file
How to exclude column in xml config file ? 如何排除xml配置文件中的列?
I want to do this serilogColumnOptions.Store.Remove(StandardColumn.Properties); 我想这样做serilogColumnOptions.Store.Remove(StandardColumn.Properties); event in config file
配置文件中的事件
Seems like it's not possible to remove Serilog columns through XML configuration. 似乎无法通过XML配置删除Serilog列。
I have found several confirmations of this statement: here and here . 我发现了这一说法的一些确认: 这里和这里 。
You could also verify this by examining source code for SQL Server Sink: 您还可以通过检查SQL Server Sink的源代码来验证这一点:
MSSqlServer()
extension method checks for MSSqlServerSettingsSection
section for configuring columns like described in documentation . MSSqlServer()
扩展方法检查“ MSSqlServerSettingsSection
部分是否配置了文档中所述的列。
MSSqlServerConfigurationSection serviceConfigSection =
ConfigurationManager.GetSection("MSSqlServerSettingsSection") as MSSqlServerConfigurationSection;
// If we have additional columns from config, load them as well
if (serviceConfigSection != null && serviceConfigSection.Columns.Count > 0)
{
if (columnOptions == null)
{
columnOptions = new ColumnOptions();
}
GenerateDataColumnsFromConfig(serviceConfigSection, columnOptions);
}
If you then examine GenerateDataColumnsFromConfig()
method you'll see that all configured columns are just added to AdditionalDataColumns
collection of ColumnOptions
. 然后,如果您检查
GenerateDataColumnsFromConfig()
方法,您会看到所有已配置的列都刚刚添加到ColumnOptions
AdditionalDataColumns
集合中。 But there is no any code for removing columns from Store
collection. 但是,没有任何代码可用于从
Store
集合中删除列。
If it's a must for your application to have file configuration for Serilog and have possibility to remove some columns, you could add simple replacement for Serilog configuration from file. 如果您的应用程序必须具有Serilog的文件配置,并且有可能删除一些列,则可以从文件中添加Serilog配置的简单替换。 Here is a sample implementation for such configuration:
这是这种配置的示例实现:
var connectionString = ConfigurationManager.AppSettings["serilog:write-to:MSSqlServer.connectionString"];
var tableName = ConfigurationManager.AppSettings["serilog:write-to:MSSqlServer.tableName"];
var autoCreateSqlTable = Convert.ToBoolean(ConfigurationManager.AppSettings["serilog:write-to:MSSqlServer.autoCreateSqlTable"]);
var excludedColumns = ConfigurationManager.AppSettings["serilog:write-to:MSSqlServer.excludedColumns"];
ColumnOptions columnOptions = new ColumnOptions();
foreach (var excludedColumn in Regex.Split(excludedColumns, ",\\s*"))
{
columnOptions.Store.Remove((StandardColumn)Enum.Parse(typeof(StandardColumn), excludedColumn, true));
}
Logger log = new LoggerConfiguration()
.WriteTo.MSSqlServer(connectionString, tableName, columnOptions: columnOptions, autoCreateSqlTable: autoCreateSqlTable)
.CreateLogger();
Here is appSettings
section: 这是
appSettings
部分:
<appSettings>
<add key="serilog:using:MSSqlSever" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=.;Database=LoggingDB;Trusted_Connection=True;"/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
<add key="serilog:write-to:MSSqlServer.excludedColumns" value="Properties, TimeStamp"/>
</appSettings>
Hope this will help you. 希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.