none
Enterprise library 5.0 RRS feed

  • Question

  • I have used the EL 5.0 to create the log. The log is created  but its writing log in two files instead of one.

    Here is name of first file name: Policy.txt

    Second file name: 28afdf13-db29-453c-8a85-2684e9895353Policy.txt

    Business want just one log file  daily from midnight.

    Here is log configuration.

    <add name="Policy Flat File" 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" header="" footer="" formatter="MAO-Privacy-Policy" rollFileExistsBehavior="Increment" rollInterval="Midnight" timeStampPattern="yyyy-MM-dd" rollSizeKB="10000" maxArchivedFiles="30" />

    Please help to fix this issue.


    • Edited by A S T Thursday, August 11, 2016 3:01 PM
    Thursday, August 11, 2016 2:59 PM

Answers

  • Hi A S T,

    According to your description, I create a demo by using code configuration. I catch a exception like this:

    Activation error occured while trying to get instance of type LogWriter, key \"\""

    Then I modify the formatter with Text Formatter, it works well with only one file.

    <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" />

    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.

    Friday, August 12, 2016 5:14 AM
    Moderator
  • Hi A S T,

    According to description and related code, I modify the configuration on my side, the full configuration as below. and only regenerate one log file.

    <?xml version="1.0" encoding="utf-8" ?>
    <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="Policy" 
                  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}{tab}Message: {message}{tab}Category: {category}{tab}Priority: {priority}{tab}EventId: {eventid}{tab}Severity: {severity}{tab}Title: {title}{tab}Activity ID: {property(ActivityId)}{tab}Machine: {localMachine}{tab}App Domain: {localAppDomain}{tab}ProcessId: {localProcessId}{tab}Process Name: {localProcessName}{tab}Thread Name: {threadName}{tab}Win32 ThreadId:{win32ThreadId}{tab}Extended Properties: {dictionary({key} - {value}{tab})}"
            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="{message}" 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>
    
      <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
        </startup>
    </configuration>

    If possible, could you please provide a simple demo which could reproduce the issue, 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, August 16, 2016 4:41 AM
    Moderator

All replies

  • Hi A S T,

    According to your description, I create a demo by using code configuration. I catch a exception like this:

    Activation error occured while trying to get instance of type LogWriter, key \"\""

    Then I modify the formatter with Text Formatter, it works well with only one file.

    <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" />

    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.

    Friday, August 12, 2016 5:14 AM
    Moderator
  • Hi Cole,

    Thanks for the reply.

    The log is created. The problem is its not creating in one file. 

    The log file name  adding extra character to file name.

    Here is the complete  configuration:

    ===================================================

    <add name="MAO Privacy Policy Flat File" 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" header="" footer="" formatter="Policy" rollFileExistsBehavior="Increment" rollInterval="Day" timeStampPattern="yyyy-MM-dd" rollSizeKB="10000" maxArchivedFiles="30" />

    <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="{message}" name="Policy" />

    ==================================================

     Please see the below file names.

    ==================================================

    Policy.2016-08-12.1.txt

    59090b33-45a8-4f97-a208-b2e0e36dc37bPolicy.2016-08-12.1.txt

    ===================================================

    Regards,

    AST

    Friday, August 12, 2016 2:16 PM
  • Hi A S T,

    Please modify the formatter to text formatter as I mention above and check if it works for you.

    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.

    Monday, August 15, 2016 9:18 AM
    Moderator
  • Hi Cole,

    The problem is the log file name is not consistent. The log is created. I already have the Text formatter in config. I need the log in below format so cannot change the formatter. The formatter is correct.

    Issue is with log file name. 

    <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="{message}" name="Policy" />

    Monday, August 15, 2016 2:25 PM
  • Hi A S T,

    According to description and related code, I modify the configuration on my side, the full configuration as below. and only regenerate one log file.

    <?xml version="1.0" encoding="utf-8" ?>
    <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="Policy" 
                  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}{tab}Message: {message}{tab}Category: {category}{tab}Priority: {priority}{tab}EventId: {eventid}{tab}Severity: {severity}{tab}Title: {title}{tab}Activity ID: {property(ActivityId)}{tab}Machine: {localMachine}{tab}App Domain: {localAppDomain}{tab}ProcessId: {localProcessId}{tab}Process Name: {localProcessName}{tab}Thread Name: {threadName}{tab}Win32 ThreadId:{win32ThreadId}{tab}Extended Properties: {dictionary({key} - {value}{tab})}"
            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="{message}" 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>
    
      <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
        </startup>
    </configuration>

    If possible, could you please provide a simple demo which could reproduce the issue, 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, August 16, 2016 4:41 AM
    Moderator