Skip to content

Sql Connection factory #609

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

Closed
wants to merge 2 commits into from

Conversation

nhart12
Copy link
Contributor

@nhart12 nhart12 commented Mar 13, 2025

Idea for
#608

nhart12 added 2 commits March 14, 2025 10:20
Signed-off-by: Nathan Hart <nhart12@gmail.com>
Signed-off-by: Nathan Hart <nhart12@gmail.com>
@nhart12 nhart12 force-pushed the sqlConnectionFactory branch from f83de79 to adf1543 Compare March 14, 2025 14:21
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
/// <returns>Logger configuration, allowing configuration to continue.</returns>
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
public static LoggerConfiguration MSSqlServer(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just add the func parameter to the existing constructor since we already have a number of constructors here (some obsolete even).

IConfigurationSection columnOptionsSection,
IApplySystemConfiguration applySystemConfiguration,
IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration)
{
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rather check the connection string for null instead of having another overload of the method which is almost identical.

public static LoggerConfiguration MSSqlServer(
this LoggerSinkConfiguration loggerConfiguration,
Func<SqlConnection> sqlConnectionFactory,
string initialCatalog,
Copy link
Member

Choose a reason for hiding this comment

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

Again: add to existing ctor with default null instead of a new ctor.

@ckadluba
Copy link
Member

Thank you for the PR.

I made some comments about adding new constructors. I'm yet not sure how to handle this. You added new constructors/methods as overloads with the new Func as a parameter but at some spots we already have a lot of differnt constructors and some are marked obsolete. So I tend to not adding new ones and rather add the Func as a default null parameter.
But on the other hand adding a new overload might be the more compatible change on the public API surface of the sink library. I will take a moment to think about this.

The most important point is another thing though. I just learned about a new issue causing exceptions under heavy load (#607). I'd really like to fix that first before going forward with the PR.

Generally I think your suggestion is a useful feature for the sink and we should add it. :)

@ckadluba
Copy link
Member

I thought about the new parameter and think it would be best to add it to the MSSqlServerSinkOptions class. This way we could remain binary compatible to older versions and not introduce yet another set of constructor overloads.

One thing that speaks against adding it to the options class is, that this class has currently only configuration data which can also be read using the .NET configuration APIs (e.g. from appsettings.json). For the connection factory this would not be the case. It can of course only be set programatically. But I think that should not stop us from adding it to options. The options class should be the primary location for new sink parameters.

@ckadluba
Copy link
Member

The fix of issue #607 is implemented, so you can rebase and proceed with this PR.

@nhart12
Copy link
Contributor Author

nhart12 commented Mar 16, 2025

Thank you. I agree with your comments regarding the additional constructors.. Instead of rebasing this one I made another pr that is hopefully a bit simpler, just extends the existing options like you said to optionally allow providing an Action that can customize the SqlConnection on creation (instead of a function which would entirely take over creation)

@nhart12 nhart12 closed this Mar 16, 2025
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