Skip to content

Commit

Permalink
Refactor: Structured logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdcastel committed Oct 25, 2024
1 parent f00a9a9 commit dbec551
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 462 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using FirebirdSql.Data.Common;
using FirebirdSql.Data.Logging;
using Microsoft.Extensions.Logging;

namespace FirebirdSql.Data.FirebirdClient;

Expand All @@ -33,7 +32,7 @@ public sealed class FbBatchCommand : IFbPreparedCommand, IDescriptorFiller, IDis
, IAsyncDisposable
#endif
{
static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbBatchCommand));
static readonly ILogger<FbBatchCommand> Log = FbLogManager.CreateLogger<FbBatchCommand>();

private const int DefaultBatchBufferSize = 16 * 1024 * 1024;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
using System.Threading.Tasks;
using FirebirdSql.Data.Common;
using FirebirdSql.Data.Logging;
using Microsoft.Extensions.Logging;

namespace FirebirdSql.Data.FirebirdClient;

public sealed class FbCommand : DbCommand, IFbPreparedCommand, IDescriptorFiller, ICloneable
{
static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbCommand));
static readonly ILogger<FbCommand> Log = FbLogManager.CreateLogger<FbCommand>();

#region Fields

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
using System.Threading.Tasks;
using FirebirdSql.Data.Common;
using FirebirdSql.Data.Logging;
using Microsoft.Extensions.Logging;

namespace FirebirdSql.Data.FirebirdClient;

[DefaultEvent("InfoMessage")]
public sealed class FbConnection : DbConnection, ICloneable
{
static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbConnection));
static readonly ILogger<FbConnection> Log = FbLogManager.CreateLogger<FbConnection>();

#region Static Pool Handling Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
using System.Threading.Tasks;
using FirebirdSql.Data.Common;
using FirebirdSql.Data.Logging;
using Microsoft.Extensions.Logging;

namespace FirebirdSql.Data.FirebirdClient;

public sealed class FbTransaction : DbTransaction
{
static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbTransaction));
static readonly ILogger<FbTransaction> Log = FbLogManager.CreateLogger<FbTransaction>();

internal const IsolationLevel DefaultIsolationLevel = IsolationLevel.ReadCommitted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<Compile Update="FirebirdClient\FbBatchCommand.cs" />
Expand Down

This file was deleted.

28 changes: 0 additions & 28 deletions src/FirebirdSql.Data.FirebirdClient/Logging/FbLogLevel.cs

This file was deleted.

33 changes: 11 additions & 22 deletions src/FirebirdSql.Data.FirebirdClient/Logging/FbLogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,26 @@

//$Authors = Jiri Cincura ([email protected])

using System;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging;

namespace FirebirdSql.Data.Logging;

public static class FbLogManager
{
public static IFbLoggingProvider Provider
{
get
{
_providerRetrieved = true;
return _provider;
}
set
{
if (_providerRetrieved)
throw new InvalidOperationException("The logging provider must be set before any action is taken");
internal static ILoggerFactory LoggerFactory = NullLoggerFactory.Instance;
internal static bool IsParameterLoggingEnabled = false;

_provider = value ?? throw new ArgumentNullException(nameof(value));
}
public static void UseLoggerFactory(ILoggerFactory loggerFactory)
{
LoggerFactory = loggerFactory;
}

public static bool IsParameterLoggingEnabled { get; set; }

static IFbLoggingProvider _provider;
static bool _providerRetrieved;

static FbLogManager()
public static void EnableParameterLogging(bool enable = true)
{
_provider = new NullLoggingProvider();
IsParameterLoggingEnabled = enable;
}

internal static IFbLogger CreateLogger(string name) => Provider.CreateLogger("FirebirdClient." + name);
internal static ILogger<T> CreateLogger<T>() =>
LoggerFactory.CreateLogger<T>();
}
43 changes: 0 additions & 43 deletions src/FirebirdSql.Data.FirebirdClient/Logging/IFbLogger.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/FirebirdSql.Data.FirebirdClient/Logging/IFbLoggingProvider.cs

This file was deleted.

Loading

0 comments on commit dbec551

Please sign in to comment.