snowflakedb / snowflake-connector-net

Snowflake Connector for .NET
Apache License 2.0
176 stars 135 forks source link

SNOW-1676298: Expose the possibility to disable logging completely (for .NET Native AOT) #1028

Open pjmvp opened 4 hours ago

pjmvp commented 4 hours ago

As of today, the constructor for SnowflakeDbConnection calls a SFLoggerFactory.GetLogger() method which in turn calls a GetLogger() method in a LogManager class from the log4net dependency.

That log4net method calls Assembly.GetCallingAssembly() which is not supported when running in native AOT.

I see that SFLoggerFactory has enableLogger and disableLogger methods. However, SFLoggerFactory is a private class so we cannot invoke them. I see no other way of telling the package to use SFLoggerEmptyImpl.

Ideally, the driver would use the ILogger interface, instead of log4net, and I see others have requested that as well. But besides that, I think that. at the very least, the package should allow us to not use any logging if we so desire. Even if one tries to do so via configuration, the SnowflakeDbConnection will always call GetLogger(). In my case, this makes it impractical (*) to use .NET Native AOT.

(*) The only way I can achieve that is with a reflection dirty-hack, using reflection methods supported in native AOT, to invoke the private method.

pjmvp commented 4 hours ago

Ref to. https://github.com/snowflakedb/snowflake-connector-net/issues/47