I am trying to set the target connectiostring value of nlog.config file from appsettings.json of the application.
I was able to do it in .Net 5.0 but same is not working with .net 6.0, Seems like here we only have Program.cs file and no Startup.cs.
I am not able to identify the proper place in Program.cs of .net 6.0 probably to run the code which is running on .net 5.0.
Can anyone please check and advise the same?
Program.cs:
//initialize logger
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); //getting error at this line
UpdateNLogConfig(builder.Configuration, builder.Environment);
static void UpdateNLogConfig(IConfiguration configuration, IHostEnvironment env)
{
var storageConnectionString = configuration.GetSection("abc-defg-sa-conn").Get<string>();
GlobalDiagnosticsContext.Set("StorageConnectionString", storageConnectionString);
var configFile = "nlog.config";
LogManager.Configuration = LogManager.LoadConfiguration(configFile).Configuration;
}
nlog.config:
<target xsi:type="AzureBlobStorage"
name="azure"
layout="${layout}"
connectionString="${gdc:item=StorageConnectionString}"
container="ssystemslogs"
blobName="${date:universalTime=true:format=yyyy-MM-dd}/${date:universalTime=true:format=HH}.log" >
</target>
