Skip to content

Commit

Permalink
🐛 fixed Serilog write to SQLite
Browse files Browse the repository at this point in the history
- create https://github.com/neozhu/serilog-sinks-sqlite project based on the fork of the serilog-sinks-sqlite project. https://github.com/saleem-mirza/serilog-sinks-sqlite
-  fixed the Serilog SQLite sink that prevented the Message, LogEvent, ClientIP, UserName, and ClientAgent fields from being properly written to the database.
  • Loading branch information
neozhu authored Dec 24, 2023
2 parents 6a3ff98 + a1b0611 commit 2cdefd2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/Infrastructure/Extensions/SerilogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static void WriteToDatabase(LoggerConfiguration serilogConfig, IConfigur
WriteToNpgsql(serilogConfig, connectionString);
break;
case DbProviderKeys.SqLite:
WriteToSqLite(serilogConfig, connectionString);
WriteToSqLite(serilogConfig, "BlazorDashboardDb.db");
break;
}
}
Expand Down Expand Up @@ -169,16 +169,15 @@ private static void WriteToNpgsql(LoggerConfiguration serilogConfig, string? con
));
}

private static void WriteToSqLite(LoggerConfiguration serilogConfig, string? connectionString)
private static void WriteToSqLite(LoggerConfiguration serilogConfig, string dbname)
{
if (string.IsNullOrEmpty(connectionString)) return;

var sqlPath = Environment.CurrentDirectory + dbname;
const string tableName = "Loggers";
serilogConfig.WriteTo.Async(wt => wt.SQLite(
connectionString,
sqlPath,
tableName,
LogEventLevel.Information
));
).CreateLogger());
}


Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="2.0.3" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.SQLite" Version="6.0.0" />
<PackageReference Include="Blazor.Serilog.Sinks.SQLite" Version="1.0.4" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="0.24.0" />

</ItemGroup>
Expand Down

0 comments on commit 2cdefd2

Please sign in to comment.