Skip to content

Ensure safe app start in case server dns problem exception is thrown#86

Open
grendizeras wants to merge 2 commits intomattwcole:devfrom
grendizeras:dns_exception_hadling
Open

Ensure safe app start in case server dns problem exception is thrown#86
grendizeras wants to merge 2 commits intomattwcole:devfrom
grendizeras:dns_exception_hadling

Conversation

@grendizeras
Copy link
Copy Markdown

When using gelf with server dns endpoint, if dns fails, application fails to start as Exception propagates to application startup, causing app to crash.

Copilot AI review requested due to automatic review settings December 18, 2025 08:37
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 prevents application crashes during startup when DNS resolution fails for the GELF logging server. The changes wrap the logger initialization in a try-catch block and return a NullLogger when the message processor fails to initialize, allowing the application to start even if the logging endpoint is unavailable.

Key Changes:

  • Added defensive null check in CreateLogger to return NullLogger.Instance when message processor initialization fails
  • Wrapped LoadLoggerOptions logic in try-catch to prevent DNS exceptions from propagating to application startup
  • Reordered using statements for consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

catch (Exception ex)
{
logger.Value.Options = options;
Console.WriteLine(ex.ToString());
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

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

The exception is being caught and silently swallowed with only a console output. This could make debugging difficult in production. Consider at minimum adding a comment explaining why exceptions are suppressed and that logging will degrade to NullLogger, or providing a more robust error handling strategy.

Suggested change
Console.WriteLine(ex.ToString());
// Swallowing exceptions here is intentional: failing to initialize or reload GELF
// logging options should not crash the application or configuration reload.
// If initialization never succeeds, _messageProcessor will remain null and
// CreateLogger will fall back to NullLogger.Instance, effectively disabling GELF logging.
// The exception details are written to the console to aid diagnostics.
Console.Error.WriteLine($"[GelfLoggerProvider] Failed to load GELF logger options: {ex}");

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants