Skip to content

Add IPv4/IPv6 preference support to ClientIpEnricher #55

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 3, 2025

This PR implements IPv4/IPv6 preference functionality for the ClientIpEnricher to allow users to specify which IP version they want to log.

Changes Made

New IpVersionPreference enum

Added enum with the following options:

  • None (default): No preference - use whatever IP version is available
  • PreferIpv4: Prefer IPv4 addresses when multiple are available, fallback to IPv6
  • PreferIpv6: Prefer IPv6 addresses when multiple are available, fallback to IPv4
  • Ipv4Only: Only log IPv4 addresses, ignore IPv6 addresses
  • Ipv6Only: Only log IPv6 addresses, ignore IPv4 addresses

Enhanced ClientIpEnricher

  • Added IP version preference parameter to constructors
  • Implemented filtering logic based on AddressFamily
  • Maintains full backward compatibility

Extended Configuration API

Added new overload to support IP version preferences:

// Existing usage continues to work unchanged
.Enrich.WithClientIp()

// New usage with IP version preference
.Enrich.WithClientIp(IpVersionPreference.Ipv4Only)
.Enrich.WithClientIp(IpVersionPreference.Ipv6Only)

Example Usage

// Only log IPv4 addresses, ignore IPv6
Log.Logger = new LoggerConfiguration()
    .Enrich.WithClientIp(IpVersionPreference.Ipv4Only)
    .WriteTo.Console()
    .CreateLogger();

// Only log IPv6 addresses, ignore IPv4  
Log.Logger = new LoggerConfiguration()
    .Enrich.WithClientIp(IpVersionPreference.Ipv6Only)
    .WriteTo.Console()
    .CreateLogger();

Testing

  • Added 15 comprehensive tests covering all preference scenarios
  • Added 3 manual validation tests demonstrating real-world usage
  • All existing tests continue to pass
  • Verified backward compatibility

Documentation

  • Updated README with usage examples and preference descriptions
  • Added comprehensive XML documentation for new APIs

Backward Compatibility

No breaking changes - all existing code continues to work without modification
✅ Default behavior remains unchanged
✅ New functionality is opt-in only

Fixes #48.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 3, 2025 11:48
Co-authored-by: mo-esmp <1659032+mo-esmp@users.noreply.github.com>
Co-authored-by: mo-esmp <1659032+mo-esmp@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] IPv4 vs IPv6 Preferences or flags Add IPv4/IPv6 preference support to ClientIpEnricher Jul 3, 2025
Copilot finished work on behalf of mo-esmp July 3, 2025 12:01
@Copilot Copilot AI requested a review from mo-esmp July 3, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IPv4 vs IPv6 Preferences or flags
2 participants