Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Structured logging. #1201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (jiri@cincura.net)

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