Logging issue for Enterprise Library 2006 on Windows Server 2012

Topics: Logging Application Block
Sep 20, 2013 at 3:38 PM
Hi,

I have running Enterprise Library 2006 on Windows server 2003 to log some info to EventLog. I transition it to Windows Server 2012 and logging stop working.
What has to be done to make Enterprise Library work on Windows Server 2012?

Thanks.
Sep 23, 2013 at 3:39 PM
Trying to write to the Event Log on a new server -- that sounds like a permission problem. Have you created your Event Sources (this requires Administrator privileges)? See http://stackoverflow.com/questions/446691/how-to-create-windows-eventlog-source-from-command-line/ for a few ways to do that.

Also, if you set the the errors special source to a flat file then you you should (hopefully) be able to see the exact error:
  <specialSources>
    <allEvents switchValue="All" name="All Events" />
    <notProcessed switchValue="All" name="Unprocessed Category" />
    <errors switchValue="All" name="Logging Errors & Warnings">
      <listeners>
        <add name="Flat File Trace Listener" />
      </listeners>
    </errors>
  </specialSources>
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Sep 24, 2013 at 10:11 PM
Thank you for reply.
eventcreate /ID 2 /L APPLICATION /T ERROR /D "Enterprise Library Logging"
It doesn't work.
Sep 25, 2013 at 6:17 AM
JS0001 wrote:
Thank you for reply.
eventcreate /ID 2 /L APPLICATION /T ERROR /D "Enterprise Library Logging"
It doesn't work.
Do you mean that the eventcreate command fails or that your application still doesn't log?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Sep 25, 2013 at 2:21 PM
eventcreate command succeeded. Enterprise Library Trace Logging doesn't work.
Sep 27, 2013 at 8:43 AM
Did you set the errors special source to write to a flat file? If so, was there any output? Can you post your configuration and code sample?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Sep 30, 2013 at 10:07 PM
<configuration>
    <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </configSections>
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
        <add fileName="C:\Users\xxxxx\Documents\EntLib31Sources\Log2006\Log2006\trace.log" header="----------------------------------------"
        footer="----------------------------------------" formatter=""
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
        traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
        name="FlatFile TraceListener" />    
            <add source="Enterprise Library Logging" formatter="Text Formatter"
                log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
                traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Formatted EventLog TraceListener" />
        </listeners>
        <formatters>
            <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
                type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Text Formatter" />
        </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
          <add name="FlatFile TraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
          <add name="FlatFile TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>
Code is C# console application.
LogEntry le = new LogEntry("test error message 1", "Error", 1, 2,  TraceEventType.Error, "", null);
            
Logger.Write(le);
There are no results, neither in a file nor in event log.
Oct 1, 2013 at 3:25 AM
Edited Oct 1, 2013 at 3:27 AM
Typically, you shouldn't configure the errors special source to use any of the trace listeners you are using for logging. This is because the errors special source is invoked when one of the trace listeners fails. If the failure was non-transient (e.g. permissions) then the errors special source will also fail and not give any indications of the nature of the error. Also note that when one trace listener fails then subsequent trace listeners will not be executed in the sequence of listeners.

Assuming that the file "C:\Users\xxxxx\Documents\EntLib31Sources\Log2006\Log2006\trace.log" exists (or the process has permission to create the file) and the process has permission to write to the file then change the errors special source to just write to the flat file:
<errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="FlatFile TraceListener" />
        </listeners>
      </errors>
Although, personally, I would prefer a separate trace listener pointing to a separate log file (e.g. ...\error.log).

Another approach to tracking down permission issues is to run Process Monitor and look for error accessing files/registry keys.


~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Oct 1, 2013 at 2:51 PM
It's a partial solution. When log file created in advance and config updated Enterprise Library starts writing to file.
Event log is still without any messages from the library. Process Monitor shows no file/registry errors.

Process Monitor helps to identify differences in an old environment (Windows Server 2003) and in a new one (Windows Server 2012).
Missing registry entries are
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Enterprise Library Logging Service]  
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\Enterprise Library Logging]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\Enterprise Library Logging Service]
in Windows Server 2012. Then above registry keys are transferred to a new environment. Enterprise Library starts logging to Event Log.