Skip to content

feat(SocketLogging): add SocketLogging function#556

Merged
ArgoZhang merged 4 commits intomasterfrom
refactor-socket
Aug 29, 2025
Merged

feat(SocketLogging): add SocketLogging function#556
ArgoZhang merged 4 commits intomasterfrom
refactor-socket

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Aug 29, 2025

Link issues

fixes #555

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add a SocketLogging utility and integrate it into TCP socket factory and data conversion components while reorganizing project namespaces under BootstrapBlazor.Socket for consistency

New Features:

  • Introduce SocketLogging static class for centralized socket-related logging

Enhancements:

  • Automatically initialize SocketLogging in DefaultTcpSocketFactory when creating clients
  • Log exceptions in DataConverter.TryConvertTo using SocketLogging

Copilot AI review requested due to automatic review settings August 29, 2025 01:04
@bb-auto bb-auto Bot added the enhancement New feature or request label Aug 29, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Aug 29, 2025
@ArgoZhang ArgoZhang merged commit f6f788e into master Aug 29, 2025
1 check passed
@ArgoZhang ArgoZhang deleted the refactor-socket branch August 29, 2025 01:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds SocketLogging functionality to the BootstrapBlazor.Socket library and performs namespace refactoring to improve code organization. The logging system provides centralized error tracking for socket operations.

  • Introduces a new SocketLogging class for centralized logging in socket operations
  • Refactors all namespaces from global BootstrapBlazor.* to BootstrapBlazor.Socket.* prefixes
  • Updates project references and configurations to support the new namespace structure

Reviewed Changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
DefaultTcpSocketFactory.cs Adds SocketLogging initialization logic in the factory
SocketLogging.cs New logging utility class with initialization and error logging methods
Multiple PropertyConverter files Namespace changes from BootstrapBlazor.DataConverters to BootstrapBlazor.Socket.DataConverters
Multiple DataHandler files Namespace changes from BootstrapBlazor.DataHandlers to BootstrapBlazor.Socket.DataHandlers
DataConverter.cs Adds exception logging using the new SocketLogging class
BinConverter.cs Namespace change with a typo in the new namespace
Project files Version updates and dependency configuration changes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

using System.Text;

namespace BootstrapBlazor.Components.DataConverter;
namespace BootstrapBlazorSocket.DataConverter;
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace has a typo - missing dot between 'BootstrapBlazor' and 'Socket'. Should be 'BootstrapBlazor.Socket.DataConverter' to match the pattern used in other files.

Suggested change
namespace BootstrapBlazorSocket.DataConverter;
namespace BootstrapBlazor.Socket.DataConverter;

Copilot uses AI. Check for mistakes.
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET9Version)" />
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .NET 8.0 target framework is incorrectly using NET9Version. Line 26 should use $(NET8Version) to match the pattern established for other .NET 8.0 dependencies.

Suggested change
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET9Version)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET8Version)" />

Copilot uses AI. Check for mistakes.
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET9Version)" />
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .NET 8.0 target framework is incorrectly using NET9Version. Line 26 should use $(NET8Version) to match the pattern established for other .NET 8.0 dependencies.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +34
<ItemGroup>
</ItemGroup>
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty ItemGroup should be removed as it serves no purpose and clutters the project file.

Suggested change
<ItemGroup>
</ItemGroup>

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +35
///
/// </summary>
/// <param name="message"></param>
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty XML documentation comment should be completed to describe the LogError method's purpose and parameters.

Suggested change
///
/// </summary>
/// <param name="message"></param>
/// Logs an error message using the configured logger.
/// </summary>
/// <param name="message">The error message to log.</param>

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +42
///
/// </summary>
/// <param name="message"></param>
public static void LogError(string message) => _logger?.LogError(message);

/// <summary>
///
/// </summary>
/// <param name="ex"></param>
/// <param name="message"></param>
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty XML documentation comment should be completed to describe the LogError overload method's purpose and parameters.

Suggested change
///
/// </summary>
/// <param name="message"></param>
public static void LogError(string message) => _logger?.LogError(message);
/// <summary>
///
/// </summary>
/// <param name="ex"></param>
/// <param name="message"></param>
/// Logs an error message using the configured logger.
/// </summary>
/// <param name="message">The error message to log.</param>
public static void LogError(string message) => _logger?.LogError(message);
/// <summary>
/// Logs an exception and an optional error message using the configured logger.
/// </summary>
/// <param name="ex">The exception to log.</param>
/// <param name="message">An optional error message to log with the exception.</param>

Copilot uses AI. Check for mistakes.
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Aug 29, 2025

🧙 Sourcery is reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider replacing the static SocketLogging.Init call in GetOrCreate with proper ILogger injection (e.g. constructor injection) to avoid global mutable state and improve testability.
  • Ensure the SocketLogging.Init path is thread-safe (for example by using a lock or Lazy initialization) to avoid race conditions when multiple sockets are created concurrently.
  • Double-check the bulk namespace refactoring for consistency and typos (e.g. missing a '.' in some BootstrapBlazorSocket.DataConverter declarations) to prevent compilation errors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider replacing the static SocketLogging.Init call in GetOrCreate with proper ILogger injection (e.g. constructor injection) to avoid global mutable state and improve testability.
- Ensure the SocketLogging.Init path is thread-safe (for example by using a lock or Lazy initialization) to avoid race conditions when multiple sockets are created concurrently.
- Double-check the bulk namespace refactoring for consistency and typos (e.g. missing a '.' in some BootstrapBlazorSocket.DataConverter declarations) to prevent compilation errors.

## Individual Comments

### Comment 1
<location> `src/extensions/BootstrapBlazor.Socket/DataConverter/BinConverter.cs:7` </location>
<code_context>

 using System.Text;

-namespace BootstrapBlazor.Components.DataConverter;
+namespace BootstrapBlazorSocket.DataConverter;

 /// <summary>
</code_context>

<issue_to_address>
Namespace change introduces inconsistency with other files.

Please update the namespace to 'BootstrapBlazor.Socket.DataConverters' for consistency with the rest of the codebase and to prevent potential type resolution issues.
</issue_to_address>

### Comment 2
<location> `src/extensions/BootstrapBlazor.Socket/DataConverter/HexConverter.cs:5` </location>
<code_context>

 using System.Text;

-namespace BootstrapBlazor.Components.DataConverter;
+namespace BootstrapBlazorSocket.DataConverter;

</code_context>

<issue_to_address>
Namespace 'BootstrapBlazor.Socket.DataConverter' is singular, while others use plural.

Consider renaming the namespace to 'BootstrapBlazor.Socket.DataConverters' to match the convention used elsewhere in the codebase.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
namespace BootstrapBlazor.Socket.DataConverter;
=======
namespace BootstrapBlazor.Socket.DataConverters;
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `src/extensions/BootstrapBlazor.TcpSocket/DefaultTcpSocketFactory.cs:20` </location>
<code_context>

     public ITcpSocketClient GetOrCreate(string name, Action<TcpSocketClientOptions> valueFactory)
     {
+        if (!SocketLogging.Inited)
+        {
+            var logger = provider.GetService<ILogger<DefaultTcpSocketFactory>>();
</code_context>

<issue_to_address>
SocketLogging initialization is performed per GetOrCreate call.

This approach can cause redundant initialization and race conditions under concurrent access. Recommend initializing SocketLogging once at startup or ensuring thread safety.

Suggested implementation:

```csharp
    public DefaultTcpSocketFactory(IServiceProvider provider)
    {
        this.provider = provider;
        // Ensure SocketLogging is initialized only once at startup
        if (!SocketLogging.Inited)
        {
            var logger = provider.GetService<ILogger<DefaultTcpSocketFactory>>();
            if (logger != null)
            {
                SocketLogging.Init(logger);
            }
        }
    }

    public ITcpSocketClient GetOrCreate(string name, Action<TcpSocketClientOptions> valueFactory)
    {
        return _pool.GetOrAdd(name, key =>
        {
            var options = new TcpSocketClientOptions();

```

- You may need to ensure that the `provider` field is defined at the class level and properly assigned in the constructor.
- If there are multiple constructors, make sure SocketLogging initialization is performed in all relevant ones.
- Remove any other redundant SocketLogging initialization from elsewhere in the class.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


using System.Text;

namespace BootstrapBlazor.Components.DataConverter;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Namespace change introduces inconsistency with other files.

Please update the namespace to 'BootstrapBlazor.Socket.DataConverters' for consistency with the rest of the codebase and to prevent potential type resolution issues.

// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

namespace BootstrapBlazor.Components.DataConverter;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Namespace 'BootstrapBlazor.Socket.DataConverter' is singular, while others use plural.

Consider renaming the namespace to 'BootstrapBlazor.Socket.DataConverters' to match the convention used elsewhere in the codebase.

Suggested change
namespace BootstrapBlazor.Components.DataConverter;
namespace BootstrapBlazor.Socket.DataConverters;


public ITcpSocketClient GetOrCreate(string name, Action<TcpSocketClientOptions> valueFactory)
{
if (!SocketLogging.Inited)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): SocketLogging initialization is performed per GetOrCreate call.

This approach can cause redundant initialization and race conditions under concurrent access. Recommend initializing SocketLogging once at startup or ensuring thread safety.

Suggested implementation:

    public DefaultTcpSocketFactory(IServiceProvider provider)
    {
        this.provider = provider;
        // Ensure SocketLogging is initialized only once at startup
        if (!SocketLogging.Inited)
        {
            var logger = provider.GetService<ILogger<DefaultTcpSocketFactory>>();
            if (logger != null)
            {
                SocketLogging.Init(logger);
            }
        }
    }

    public ITcpSocketClient GetOrCreate(string name, Action<TcpSocketClientOptions> valueFactory)
    {
        return _pool.GetOrAdd(name, key =>
        {
            var options = new TcpSocketClientOptions();
  • You may need to ensure that the provider field is defined at the class level and properly assigned in the constructor.
  • If there are multiple constructors, make sure SocketLogging initialization is performed in all relevant ones.
  • Remove any other redundant SocketLogging initialization from elsewhere in the class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(SocketLogging): add SocketLogging function

2 participants