Confusing "Malfunction" with Configfile & eventlogging

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Confusing "Malfunction" with Configfile & eventlogging

Hello guys,

We want to use NLog for your package-installations with SCCM.

We want to log in a local logfile (Variable: "Logfile"), which should have the packagename as filename (Variable: "Packagename" -> Value comes from Registry). This works really fine, but a problem occurs when we want to create log entires in the eventlog at the same time.

It seems that there is a problem resolving the variable ${packagename} along with the target parmeter "source" for eventlogging. The parameter ${packagename} still works, when I use it in the variable for the eventlog layout ${event} - twice. But i want it to use as source too. So I can see easily what Package has caused the eventlog-entry.
If I change the value for ${packagename} to a simple string like "TEST", everything works fine. But at the moment as I change it, to be read out from the registry, eventlogging doesn't work.

Any ideas?

PS: I actually use Nlog via COM along with vbscript (powershell in near future).

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns=""
      xmlns:xsi="" autoReload="true">

        <variable name="packagename" value="${registry:value=LastPackage:key=HKLM\\SOFTWARE\\MyCompany\\SCCM-Packages:defaultValue=WrapperTemplate}"/>
        <variable name="LogFile" value="${environment:variable=systemroot}\System32\LogFiles\packages\${packagename}.log"/>
        <variable name="brief" value="${date} | ${logger} | ${level:uppercase=true} | ${windows-identity} | ${message}"/>
        <variable name="verbose" value="${longdate} | ${logger} | ${level:uppercase=true} | ${machine} | ${windows-identity} | ${processid} | ${processname} | ${message}"/>
        <variable name="event" value="Package: ${packagename}${newline}Script: ${logger}${newline}Process: ${processname}${newline}Process ID: ${processid}${newline}Message: ${message}${newline}${newline}For further details refer to logfile:${newline}${LogFile}"/>
        <target xsi:type="File" name="GlobalLogDir" fileName="${LogFile}" layout="${brief}"/>
        <target xsi:type="EventLog" name="EventLog" layout="${event}" source="${packagename}" log="Softwareinstallation"/>

        <logger name="*" minlevel="Trace" writeTo="GlobalLogDir"/>
        <logger name="*" levels="Info,Warn,Error" writeTo="EventLog"/>