Note that there are some explanatory texts on larger screens.

plurals
  1. PONLog configuration across AppDomains
    text
    copied!<p>I have a service that loads a dll into a seperate appdomain(the appdomain is needed because the dll is loading a dynamically generated assembly and needs to be able to unload them)</p> <p>How can I copy the nlog configuration so that the new appdomain uses the same settings?</p> <p>One additional complication is that I setup logging parameters using the GlobalDiagnosticsContext at the beginning of the program. Is there any option besides having to set them over again in each appdomain?</p> <pre><code>static void Main() { // Setup NLog variables GlobalDiagnosticsContext.Set("ConnectionString", @"..."); GlobalDiagnosticsContext.Set("ApplicationName", @"appName"); // ... loads appdomain and does logging from the new appdomain </code></pre> <p>This is my config file:</p> <pre><code>&lt;?xml version="1.0" ?&gt; &lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;variable name="TextErrorLayout" value ="${gdc:item=ApplicationName} ${date:format=yyyy-MM-dd HH\:mm\:ss.fff}${newline} Level: ${level}${newline} Description: ${message}${newline} Machine: ${machinename}${newline} User: ${windows-identity}${newline} Process: ${processname}${newline} WorkingDir: ${basedir}${newline} Exception: ${exception:format=tostring}${newline} DetailedMessage: ${event-context:item=Details}${newline}"/&gt; &lt;targets async="true"&gt; &lt;target name="LogMill" xsi:type="FallbackGroup"&gt; &lt;target xsi:type="Database" connectionString="${gdc:item=ConnectionString}" commandText="exec dbo.Usp_Log_CreateWithExtended @applicationName, @logLevel, @entryDate, @description, @machineName, @userName, @assembly, @workingDirectory, @exception, @detailedMessage"&gt; &lt;dbProvider&gt;mssql&lt;/dbProvider&gt; &lt;parameter name="@applicationName" layout="${gdc:item=ApplicationName}"/&gt; &lt;parameter name="@logLevel" layout="${level}"/&gt; &lt;parameter name="@entryDate" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}"/&gt; &lt;parameter name="@description" layout="${message}"/&gt; &lt;parameter name="@machineName" layout="${machinename}"/&gt; &lt;parameter name="@userName" layout="${windows-identity}"/&gt; &lt;parameter name="@assembly" layout="${processname}"/&gt; &lt;parameter name="@workingDirectory" layout="${basedir}"/&gt; &lt;parameter name="@exception" layout="${exception:format=tostring}"/&gt; &lt;parameter name="@detailedMessage" layout="${event-context:item=Details}"/&gt; &lt;/target&gt; &lt;target xsi:type="File" fileName="LogMill-FailSafe.log" layout="${TextErrorLayout}"/&gt; &lt;/target&gt; &lt;target name="EmailDevelopers" xsi:type="Mail" smtpServer="smtp.local" from="errors@email.com" to="email@email.com" subject="${gdc:item=ApplicationName} ${level} Error: ${message}" layout="${TextErrorLayout}"/&gt; &lt;target name="Console" xsi:type="ColoredConsole" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fff} ${message} ${exception:format=tostring}"/&gt; &lt;/targets&gt; &lt;rules&gt; &lt;logger name="*" minlevel="Info" writeTo="LogMill" /&gt; &lt;logger name="*" minlevel="Error" writeTo="EmailDevelopers" /&gt; &lt;/rules&gt; &lt;/nlog&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload