Reputation: 598
I am trying to write log to MsSql server using serilog. My application is .Net Core 2.1 console Application.I am using Serilog MsSql sink
I have created a table using following sql command
CREATE TABLE [Logs] (
[Id] int IDENTITY(1,1) NOT NULL,
[Message] nvarchar(max) NULL,
[MessageTemplate] nvarchar(max) NULL,
[Level] nvarchar(128) NULL,
[TimeStamp] datetimeoffset(7) NOT NULL, -- use datetime for SQL Server pre-2008
[Exception] nvarchar(max) NULL,
[Properties] xml NULL
CONSTRAINT [PK_Logs]
PRIMARY KEY CLUSTERED ([Id] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
) ON [PRIMARY];
My c# code:
static void Main(string[] args)
{
try
{
Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.MSSqlServer("Server=xyz;Database=abc;Trusted_Connection=True;", "Logs")
.CreateLogger();
Log.Information("Hello");
}
catch (Exception ex)
{
throw;
}
}
My problem is serilog doesn't write to database also It doesn't show any error. I tried to connect using Ado.Net it's connecting and inserting.But using serilog it doesn't work. What I am missing?
Upvotes: 3
Views: 5700