Custom Logging with Personal Fields in Nlog
Setting the database string via var databaseTarget = ( DatabaseTarget ) LogManager . Configuration . FindTargetByName ( "database" ); databaseTarget . ConnectionString = connectionString ; LogManager . ReconfigExistingLoggers (); The above didn't work but I used the example below where I set it via the program's start. var defaultConnection = Configuration.GetConnectionString("DefaultConnection"); NLog.GlobalDiagnosticsContext.Set("defaultConnection", defaultConnection); var logger = LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger(); Then you can use ${gdc:item=defaultConnection} in your nlog.config: <target xsi:type="Database" connectionString="${gdc:item=defaultConnection}" /> Rather than using GDC, which is for global static data and fails on concurrent logging, it is better to use EventProperties-Layout-Renderer which allows to pass of custom properties specific to the