0

Hi I posted this to the log4net user group but thought I'd post it here as well.

I'm working on a project that requires Azure MSI to connection from Azure PaaS to Azure SQL. Wondering if log4net’s ADOAppender supports this already connection mechanism already. From what I can tell it doesn't but thought I'd ask the community before extending log4net.

To support MSI apps can’t connect to a database with a connectionstring alone, they need to get an access token from Azure and then set the AccessToken property on the SqlConnection object. Like the code below is doing:

private static SqlConnection GetSqlConnection()
        {
            var sqlConnection = new SqlConnection(GetConnectionString());

            if (sqlConnection.DataSource != "(localdb)\\MSSQLLocalDB")
                sqlConnection.AccessToken = new AzureServiceTokenProvider()
                    .GetAccessTokenAsync("https://database.windows.net/").Result;

            return sqlConnection;
        }

This code is using two Microsoft nuget packages to get the access token.

Thanks!

cobolstinks
  • 6,801
  • 16
  • 68
  • 97
  • So to clarify, you're trying to utilize Log4net's ADOAppender with Azure SQL to log events from Azure SQL, and you need to add the access token to the Log4Net ADOAppender to access the SQL server? And the question is, is there a way to add an access token the Log4net's ADOAppender? – Frank H Jul 02 '19 at 00:19
  • @FrankHuMSFT " is there a way to add an access token the Log4net's ADOAppender" - Correct that is the question. I don' think there is a way and I don't think there is a log4net appender that supports this. I've since moved on from this but I don't think there is a way to log out log4net messages to Azure SQL from Azure PaaS or Azure VMS via MSI without writing a custom appender. – cobolstinks Jul 02 '19 at 13:29

0 Answers0