none
Remove Enterprise Logging Default Log parameters & Set Local time RRS feed

  • Question

  • Dear sir/miss

    I created a shared configuration to set my enterprise library so that I can use it from different types of projects/applications within one Solution in the Visual Studio. I have created my own template but the logs till some issues. In the Result logs sample,

    (1) I still get a number of categories which are not stated in my formatter which I have highlighted in bold.
    (2) Also I realised the TimeStamp which I stated in the "Text Formatter" is giving GMT -8 even thought I set as (local) but giving the correct one in "Policy"

    Thank you for any help you can provide me with.

    I have added the code snippet below:


    App.Config

    <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source" parentSource="Shared Config">
        <sources>
          <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add name="Shared Config" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
               filePath="D:\Users\muthukumaran\Documents\Visual Studio 2013\Projects\Polycom Crestron\Backend AppConfig\External.config" />
        </sources>
    < /enterpriseLibrary.ConfigurationSource>

    External.Config

          <add name="Common Service Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            fileName="C:\PolycomLogs\CommonService.log" formatter="Policy"
            rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="5000"
            timeStampPattern="dd-MM-yyyy " maxArchivedFiles="30" />
        </listeners>

     <formatters>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            template="Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;Process Name: {localProcessName}" name="Text Formatter" />

          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;" name="Policy" />
        </formatters>

     <categorySources>      
           <add switchValue="All" name="CommonServiceLog">
            <listeners>
              <add name="Common Service Trace Listener" />
            </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="Common Service Trace Listener" />
             </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>

    Result Logs Sample

    Timestamp: 8/17/2016 5:35:22 PM

    Message: Timestamp: 8/17/2016 9:35:22 AM
    Message: Device information added.
    Category:
    Priority: -1
    EventId: 0
    Severity: Information
    Title: Information in Class name: DatabaseQuery.cs, Method name: GetPhoneInformation
    Machine: APPS
    App Domain: Backend Windows Service.exe
    ProcessId: 110036
    Process Name: C:\inetpub\wwwroot\PolycomCrestronWindowsService\bin\Debug\Backend Windows Service.exe
    Thread Name:
    Win32 ThreadId:49052
    Extended Properties:

    Wednesday, August 24, 2016 6:37 AM

All replies

  • Hi MK.77,

    According to your configuration, I create a demo and try to reproduce your issue on my side by using Enterprise Library 5.0 (Build 505).  unfortunately, I could not reproduce your issue on my side, it works fine, I would suggest that you could upgrade your  Enterprise Library to Build 505.

    #use Text Formatter

    #use Policy

    Timestamp: 8/25/2016 11:01:31 AM
    Message: First message
    
    Timestamp: 8/25/2016 11:01:32 AM
    Message: Second message

    #Configuration.

    <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
      </configSections>
      <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="Important" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
          <add name="Rolling Flat File Trace Listener"
               type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
               listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
               fileName="C:\logs\Policy.txt" footer="" header=""
                  formatter="Text Formatter" 
                  rollFileExistsBehavior="Increment" 
                  rollInterval="Midnight" timeStampPattern="yyyy-MM-dd" rollSizeKB="10000"
                  maxArchivedFiles="30" />
        </listeners>
        <formatters>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
            template="Timestamp: {timestamp(local)}{tab}Message: {message}{tab}Category: {category}{tab}Priority: {priority}{tab}EventId: {eventid}{tab}ActivityId: {property(ActivityId)}{tab}Severity: {severity}{tab}Title:{title}{tab}"
            name="Brief Format Text" />
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
            template="Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;Process Name: {localProcessName}"
            name="Text Formatter" />
        
           <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
                template="Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;" name="Policy" />
        </formatters>
        <logFilters>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging"
            minimumPriority="2" maximumPriority="99" name="Priority Filter" />
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging"
            enabled="true" name="LogEnabled Filter" />
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging"
            categoryFilterMode="AllowAllExceptDenied" name="Category Filter">
            <categoryFilters>
              <add name="BlockedByFilter" />
            </categoryFilters>
          </add>
        </logFilters>
        <categorySources>
          <add switchValue="All" name="Important">
            <listeners>
              <!--<add name="Formatted EventLog TraceListener" />-->
              <add name="Rolling Flat File Trace Listener" />
            </listeners>
          </add>
        </categorySources>
        <specialSources>
          <allEvents switchValue="All" name="All Events" />
          <notProcessed switchValue="All" name="Unprocessed Category">
            <listeners>
              <!--<add name="UnprocessedFlatFile" />-->
            </listeners>
          </notProcessed>
          <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
              <!--<add name="Formatted EventLog TraceListener" />-->
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, August 25, 2016 5:10 AM
    Moderator
  • Hi Cole Wu,

    Thank you for your kind advise. I upgraded Enterprise Library to 5.0.505 but I am still getting the same result.
    Is there anything I am not doing correctly for my Configuration? Could I be writing to my logs wrongly?

    writing to Logs code
     public void CreateLog(LogData logData)
                {
                    LogEntry logEntry = new LogEntry();
                    logEntry.Title = logData.title;
                    logEntry.Message = logData.message;
                    logEntry.Severity = logData.eventType; //Information;error etc
                   
                    Logger.Write(logEntry, logData.logSource.ToString()); // logsource: WebServiceLog/WindowsServiceLog/CommonServiceLog etc
                }

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <!--  For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468  -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <section name="commonConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null" />
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
      </configSections>
      <loggingConfiguration tracingEnabled="true" defaultCategory="General">
        <listeners>
          <add name="Web Service Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            fileName="C:\PolycomLogs\WCFWebService.log" formatter="Text Formatter"
            rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="5000"
            timeStampPattern="dd-MM-yyyy " maxArchivedFiles="30" />

          <add name="Windows Service Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            fileName="C:\PolycomLogs\WindowsService.log" formatter="Text Formatter"
            rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="5000"
            timeStampPattern="dd-MM-yyyy " maxArchivedFiles="30" />

          <add name="Common Service Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            fileName="C:\PolycomLogs\CommonService.log" formatter="Text Formatter"
            rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="5000"
            timeStampPattern="dd-MM-yyyy " maxArchivedFiles="30" />
        </listeners>
        <formatters>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            template="Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;Process Name: {localProcessName}" name="Long Format Text" />
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
             template="Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;" name="Text Formatter" />
        </formatters>  
        <categorySources>
          <add switchValue="All" name="WebServiceLog">
            <listeners>
              <add name="Web Service Trace Listener" />
            </listeners>
          </add>
          <add switchValue="All" name="WindowsServiceLog">
            <listeners>
              <add name="Windows Service Trace Listener" />
            </listeners>
          </add>
          <add switchValue="All" name="CommonServiceLog">
            <listeners>
              <add name="Common Service Trace Listener" />
            </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="Web Service Trace Listener" />
              <add name="Windows Service Trace Listener" />
              <add name="Common Service Trace Listener" />-->
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
    </configuration>

    result

    ----------------------------------------
    Timestamp: 8/31/2016 1:45:04 AM

    Message: Timestamp: 8/30/2016 5:45:04 PM
    Message: Send Alert timer called
    Category:
    Priority: -1
    EventId: 0
    Severity: Information
    Title: Information in Class name: ActivatePhoneAlertService.cs, Method name: SendAlertTimer
    Machine: APPS
    App Domain: Backend Windows Service.exe
    ProcessId: 76628
    Process Name: C:\inetpub\wwwroot\PolycomCrestronWindowsService\bin\Debug\Backend Windows Service.exe
    Thread Name:
    Win32 ThreadId:122616
    Extended Properties:


    ----------------------------------------

    Tuesday, August 30, 2016 6:09 PM
  • Hi MK.77,

    Could you please provide a simple demo via OneDrive, we'll reproduce your issue on our side and try to find a solution to resolve it.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 6, 2016 9:44 AM
    Moderator
  • Hi Cole Wu,

    I found out the issue and it lies within the CreateLog code itself. 

    Instead of  'Logger.Write(logEntry, logData.logSource.ToString())' ,
    I have to use  
    'Logger.Write(logEntry)' ,

    It works fine now. Thank you for all the help you have provided me with.

    code sample:
    public void CreateLog(LogData logData)

    {
         LogEntry logEntry = new LogEntry();
         logEntry.Title = logData.title;
         logEntry.Message = logData.message;
         logEntry.Severity = logData.eventType; //Information;error etc
                   
        Logger.Write(logEntry, logData.logSource.ToString()); // logsource: WebServiceLog/ WindowsServiceLog/ CommonServiceLog etc
    }

    Wednesday, October 12, 2016 3:28 AM