NLog von Appsettings mit benutzerdefinierten AppsettingsC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 NLog von Appsettings mit benutzerdefinierten Appsettings

Post by Anonymous »

Ich habe eine benutzerdefinierte Appsettings-JSON-Datei, die ich zur Konfiguration hinzufügen muss. Ich mache dies im Hook „ConfigureAppConfiguration“, der von „CreateHostBuilder“ aufgerufen wird und von „Main“ in Program.cs aufgerufen wird. Ich verwende auch NLog.

Code: Select all

public static void Main(string[] args)
{
//
// currently using nlog.config but I want to use appsettings but they haven't been "built" yet
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
try
{
logger.Debug("init main");
CreateHostBuilder(args).Build().Run();
// could move configurenlog call here, but already called "UseNLog()"
}
catch (Exception exception)
{
logger.Error(exception, "Stopped program because of exception");
throw;
}
finally
{
NLog.LogManager.Shutdown();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) => {
// add custom config file
config
.AddJsonFile("customsettings.json", optional:true, reloadOnChange:true);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseNLog();  // NLog: Setup NLog for Dependency injection
Jetzt möchte ich die (kombinierten) Appsettings verwenden, um nlog wie hier beschrieben zu konfigurieren, aber wie mache ich das, NACHDEM ich meine benutzerdefinierten Konfigurationseinstellungen geladen habe?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post
  • NLOG aus Appsetings mit benutzerdefinierten Appsettings
    by Anonymous » » in C#
    0 Replies
    26 Views
    Last post by Anonymous
  • Verwenden einer Bibliothek von Drittanbietern, die von einer .NET 6 -Anwendung von NLOG abhängt
    by Anonymous » » in C#
    0 Replies
    40 Views
    Last post by Anonymous
  • Nlog.web.aspnetcore 5.3.12 erhöht system.uriformatexception mit net9.0
    by Anonymous » » in C#
    0 Replies
    35 Views
    Last post by Anonymous
  • Eigenschaftswerte mit NLOG zusammenführen
    by Anonymous » » in C#
    0 Replies
    30 Views
    Last post by Anonymous
  • Eigenschaftswerte mit NLOG zusammenführen
    by Anonymous » » in C#
    0 Replies
    35 Views
    Last post by Anonymous