Skip to content

Commit

Permalink
Fix #1495 - additional parameters for SQLite logging
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jul 3, 2024
1 parent 006ed5c commit e5c915a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/Shiny.Logging.Sqlite/LoggingSqliteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class LogStore
[PrimaryKey]
public int Id { get; set; }

public string Category { get; set; }
public string Message { get; set; }
public string StackTrace { get; set; }
public int EventId { get; set; }
// public string? Parameters { get; set; }
public LogLevel LogLevel { get; set; }
Expand Down
19 changes: 5 additions & 14 deletions src/Shiny.Logging.Sqlite/SqliteLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@
namespace Shiny.Logging.Sqlite;


public class SqliteLogger : ILogger
public class SqliteLogger(string categoryName, LogLevel configLogLevel, LoggingSqliteConnection conn) : ILogger
{
readonly LogLevel configLogLevel;
readonly LoggingSqliteConnection conn;


public SqliteLogger(LogLevel logLevel, LoggingSqliteConnection conn)
{
this.configLogLevel = logLevel;
this.conn = conn;
}


public IDisposable BeginScope<TState>(TState state) => NullScope.Instance;
public bool IsEnabled(LogLevel logLevel) => logLevel >= this.configLogLevel;
public bool IsEnabled(LogLevel logLevel) => logLevel >= configLogLevel;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!this.IsEnabled(logLevel))
return;

var message = formatter(state, exception);
this.conn.GetConnection().Insert(new LogStore
conn.GetConnection().Insert(new LogStore
{
Category = categoryName,
StackTrace = exception?.ToString() ?? String.Empty,
Message = message,
EventId = eventId.Id,
LogLevel = logLevel,
Expand Down

0 comments on commit e5c915a

Please sign in to comment.