diff --git a/src/Serilog.Sinks.AzureLogAnalytics.csproj b/src/Serilog.Sinks.AzureLogAnalytics.csproj
index bf8ddc6..b68c1ae 100644
--- a/src/Serilog.Sinks.AzureLogAnalytics.csproj
+++ b/src/Serilog.Sinks.AzureLogAnalytics.csproj
@@ -44,6 +44,7 @@
$(Version)-$(VersionSuffix)
+
diff --git a/src/Sinks/AzureLogAnalytics/AzureLogAnalyticsSink.cs b/src/Sinks/AzureLogAnalytics/AzureLogAnalyticsSink.cs
index 6e08691..de8ab47 100644
--- a/src/Sinks/AzureLogAnalytics/AzureLogAnalyticsSink.cs
+++ b/src/Sinks/AzureLogAnalytics/AzureLogAnalyticsSink.cs
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+using Azure.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
@@ -124,6 +125,14 @@ protected override async Task WriteLogEventAsync(ICollection log
}
private async Task GetAuthToken()
{
+ if (_loggerCredential.TokenCredential != null)
+ {
+ var tokenContext = new TokenRequestContext(new String[] { scope });
+ var cancellationToken = new CancellationToken();
+ var access_token = await _loggerCredential.TokenCredential.GetTokenAsync(tokenContext, cancellationToken);
+ return access_token.Token;
+ }
+
var uri = $"https://login.microsoftonline.com/{_loggerCredential.TenantId}/oauth2/v2.0/token";
var content = new FormUrlEncodedContent(new[]{
diff --git a/src/Sinks/AzureLogAnalytics/LoggerCredential.cs b/src/Sinks/AzureLogAnalytics/LoggerCredential.cs
index 2dafc55..52e8195 100644
--- a/src/Sinks/AzureLogAnalytics/LoggerCredential.cs
+++ b/src/Sinks/AzureLogAnalytics/LoggerCredential.cs
@@ -1,3 +1,4 @@
+using Azure.Core;
using System;
namespace Serilog.Sinks.AzureLogAnalytics
@@ -10,5 +11,6 @@ public class LoggerCredential
public String TenantId { get; set; }
public String ClientId { get; set; }
public String ClientSecret { get; set; }
+ public TokenCredential TokenCredential { get; set; }
}
}
\ No newline at end of file