我正在尝试将自定义列添加到我的日志记录数据库,但是我得到了 TargetInvocationException。它在我添加之前工作MSSqlServerSettingsSection(因此没有自定义列),所以我可能在那里遗漏了一些东西。但是,查看https://github.com/serilog/serilog-sinks-mssqlserver上的示例,我无法弄清楚我需要什么。MSSqlServer 接收器设置:<MSSqlServerSettingsSection> <Columns> <add ColumnName="JobId" DataType="nvarchar" DataLength="256" AllowNull="True"/> </Columns></MSSqlServerSettingsSection>应用程序配置:<configuration> <configSections> <section name="MSSqlServerSettingsSection" type="Serilog.Configuration.MSSqlServerConfigurationSection, Serilog.Sinks.MSSqlServer"/> </configSections> <MSSqlServerSettingsSection configSource="Configs\Shared.Serilog.MSSqlServerSettings.config" /> <appSettings> <add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" /> <add key="serilog:write-to:MSSqlServer.connectionString" value="Server=127.0.0.1; Database=LogDB; User Id=Serilog; Password=Password123;" /> <add key="serilog:write-to:MSSqlServer.tableName" value="Logs" /> <add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="false" /> <add key="serilog:write-to:MSSqlServer.restrictedToMinimumLevel" value="Verbose" /> </appSettings></configuration>创建查询:CREATE TABLE [dbo].[Logs]( [Id] int IDENTITY(1,1) NOT NULL, [Message] nvarchar(max) NULL, [MessageTemplate] nvarchar(max) NULL, [Level] nvarchar(128) NULL, [TimeStamp] datetime NOT NULL, [Exception] nvarchar(max) NULL, [Properties] nvarchar(max) NULL, [JobId] nvarchar(256) NULL CONSTRAINT [PK_Logs] PRIMARY KEY CLUSTERED ([Id] ASC), )DI 使用统一:container.RegisterInstance<ILogger>(new LoggerConfiguration() .Enrich .FromLogContext() .ReadFrom .AppSettings() .CreateLogger());Log.Logger = container.Resolve<ILogger>();
1 回答
慕雪6442864
TA贡献1812条经验 获得超5个赞
我收到以下异常
System.Configuration.ConfigurationErrorsException: 'Unrecognized attribute 'DataLength'. Note that attribute names are case-sensitive.'
不知道这是为什么,根据文档它应该是正确的。删除此行在 'AllowNull' 上给了我同样的问题。
删除两条线似乎有效。
- 1 回答
- 0 关注
- 86 浏览
添加回答
举报
0/150
提交
取消