我正在嘗試將自定義列添加到我的日志記錄數(shù)據(jù)庫,但是我得到了 TargetInvocationException。它在我添加之前工作MSSqlServerSettingsSection(因此沒有自定義列),所以我可能在那里遺漏了一些東西。但是,查看https://github.com/serilog/serilog-sinks-mssqlserver上的示例,我無法弄清楚我需要什么。MSSqlServer 接收器設(shè)置:<MSSqlServerSettingsSection> <Columns> <add ColumnName="JobId" DataType="nvarchar" DataLength="256" AllowNull="True"/> </Columns></MSSqlServerSettingsSection>應(yīng)用程序配置:<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>創(chuàng)建查詢: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 使用統(tǒng)一:container.RegisterInstance<ILogger>(new LoggerConfiguration() .Enrich .FromLogContext() .ReadFrom .AppSettings() .CreateLogger());Log.Logger = container.Resolve<ILogger>();
1 回答

慕雪6442864
TA貢獻1812條經(jīng)驗 獲得超5個贊
我收到以下異常
System.Configuration.ConfigurationErrorsException: 'Unrecognized attribute 'DataLength'. Note that attribute names are case-sensitive.'
不知道這是為什么,根據(jù)文檔它應(yīng)該是正確的。刪除此行在 'AllowNull' 上給了我同樣的問題。
刪除兩條線似乎有效。
- 1 回答
- 0 關(guān)注
- 114 瀏覽
添加回答
舉報
0/150
提交
取消