Event viewer is not picking up the category or Level

May 11, 2012 at 7:40 PM

Hi,

I am trying to log to Event Log.  It is logging everything very fine.  But, the thing is...in the event viewer it is showing the Level as "Information" and Category as "None"...even though I am forwarding Level as "Error" and all.  

I tried to attach the screenshot of it...but I was not able to do that.  So, please look into it and let me know as early as possible.

 

Thanks

Pavan

 

May 12, 2012 at 9:19 AM

Can you post the logging configuration and the code that writes to the event log?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

May 14, 2012 at 4:45 PM

 

 <listeners>
      <add name="Database Trace Listener" type="RatabaseLogging.ExtendedFormattedDatabaseTraceListener, RatabaseLogging"
        listenerDataType="RatabaseLogging.ExtendedFormattedDatabaseTraceListenerData, RatabaseLogging"
        databaseInstanceName="SQL" writeLogStoredProcName="WriteLog"
        addCategoryStoredProcName="AddCategory" formatter="Text Formatter" />
      <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="trace.log" formatter="FlatFile Formatter" />
      <add name="Event Log Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="Enterprise Library Logging" formatter="Text Formatter" />
    </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}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        Message: {message}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        Category: {category}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        LogEntryID: {property(LogEntryID)}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        SourceValue: {property(SourceValue)}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        TypeValue: {property(TypeValue)}{newline}&#xD;&#xA;&#xD;&#xA;   &#xD;&#xA;        SeverityValue: {property(SeverityValue)}{newline}&#xD;&#xA;&#xD;&#xA;        &#xD;&#xA;        Title:{title}{newline}"
        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}{newline}&#xD;&#xA;&#xD;&#xA;        Message: {message}{newline}&#xD;&#xA;&#xD;&#xA;        Category: {category}{newline}&#xD;&#xA;&#xD;&#xA;        LogEntryID: {property(LogEntryID)}{newline}&#xD;&#xA;&#xD;&#xA;        SourceValue: {property(SourceValue)}{newline}&#xD;&#xA;&#xD;&#xA;        TypeValue: {property(TypeValue)}{newline}&#xD;&#xA;&#xD;&#xA;        SeverityValue: {property(SeverityValue)}{newline}&#xD;&#xA;&#xD;&#xA;        Title:{title}{newline}&#xD;&#xA;&#xD;&#xA;        LogMessage:{property(LogMessage)}{newline}"
        name="FlatFile Formatter" />
    </formatters>



public void Log(string CategoryValue, string SeverityValue, string SourceValue, string TypeValue, string SvcID, string TitleValue, string MessageValue)
        {
            CustomLogEntry lEntry = new CustomLogEntry();

            lEntry.Categories.Add(CategoryValue);
            lEntry.Title = TitleValue;
            lEntry.Message = MessageValue;
            lEntry.SourceValue = SourceValue;
            lEntry.SeverityValue = SeverityValue;
            lEntry.TypeValue = TypeValue;
            lEntry.SvcID = SvcID;
            //lEntry.LogMessage = string.Empty;

            String strGUID = Guid.NewGuid().ToString();

            lEntry.LogEntryID = strGUID;

            Task.Factory.StartNew(() => LogMessageAsync(lEntry));
        }



Actually, in Description part of Event Viewer....it is showing exactly what we are sending.  But, when we open the 
EventViewer > Application ..... it is listing out all the events.  In that list of events....it shows the Type as "Information" and
Category as "None".  Even though the Description of the Event Viewer is having other values.



May 14, 2012 at 6:51 PM

Can you post how you are calling the Log() method that recreates the behavior?

In terms of Category, the Event Log category is not related to the Enterprise Library category so the Event Log category will not display the Enterprise Library category.   This is by design.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

May 16, 2012 at 6:06 AM
Did you add items to the Catagories List? Something similar to this
LogEntry logEntry = new LogEntry();
logEntry.EventId = 101;
logEntry.Priority = 1;
logEntry.Severity = System.Diagnostics.TraceEventType.Stop;
logEntry.Message = "The Employee Dataset got Cached by WCF Service. The User is: " + "OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name";
logEntry.Categories.Add("Trace");
logEntry.Categories.Add("UI Events");
Logger.Write(logEntry);
May 16, 2012 at 6:17 AM
Edited May 16, 2012 at 6:33 AM

@pavan329, can you also post the entire logging configuration -- you only posted the formatters and listeners.  Also, can you post the code for the CustomLogEntry class as well as the LogMessageAsync() method?

Are you actually setting the Severity property anywhere?  The default value for Severity is Information and I don't see the Severity in the code sample (although it's not clear what may be happening in the CustomLogEntry class).

Thanks,

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

May 16, 2012 at 2:40 PM

 

public class CustomLogEntry : Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry
    {

        private string logentryID;
        private string logMessage;
        private string sourceValue;
        private string typeValue;
        private string severityvalue;
        private string svcID;


        //private int logmessagelength;
       
        /// <summary>
        /// The Win32 process ID for the current running process.
        /// </summary>
        public string LogEntryID
        {
            get { return this.logentryID; }
            set { this.logentryID = value; }
        }

        public string SvcID
        {
            get { return this.svcID; }
            set { this.svcID = value; }
        }

        public string LogMessage
        {
            get { return this.logMessage; }
            set { this.logMessage = value; }
        }

        public string SourceValue
        {
            get { return this.sourceValue; }
            set { this.sourceValue = value; }
        }

        public string SeverityValue
        {
            get { return this.severityvalue; }
            set { this.severityvalue = value; }
        }

        public string TypeValue
        {
            get { return this.typeValue; }
            set { this.typeValue = value; }
        }

       
    }
}

<?xml version="1.0"?>
<configuration>

  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Database Trace Listener" type="RatabaseLogging.ExtendedFormattedDatabaseTraceListener, RatabaseLogging"
        listenerDataType="RatabaseLogging.ExtendedFormattedDatabaseTraceListenerData, RatabaseLogging"
        databaseInstanceName="SQL" writeLogStoredProcName="WriteLog"
        addCategoryStoredProcName="AddCategory" formatter="Text Formatter" />
      <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="trace.log" formatter="FlatFile Formatter" />
      <add name="Event Log Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="Enterprise Library Logging" formatter="Text Formatter" />
    </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}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        Message: {message}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        Category: {category}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        LogEntryID: {property(LogEntryID)}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        SourceValue: {property(SourceValue)}{newline}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;        TypeValue: {property(TypeValue)}{newline}&#xD;&#xA;&#xD;&#xA;   &#xD;&#xA;        SeverityValue: {property(SeverityValue)}{newline}&#xD;&#xA;&#xD;&#xA;        &#xD;&#xA;        Title:{title}{newline}"
        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}{newline}&#xD;&#xA;&#xD;&#xA;        Message: {message}{newline}&#xD;&#xA;&#xD;&#xA;        Category: {category}{newline}&#xD;&#xA;&#xD;&#xA;        LogEntryID: {property(LogEntryID)}{newline}&#xD;&#xA;&#xD;&#xA;        SourceValue: {property(SourceValue)}{newline}&#xD;&#xA;&#xD;&#xA;        TypeValue: {property(TypeValue)}{newline}&#xD;&#xA;&#xD;&#xA;        SeverityValue: {property(SeverityValue)}{newline}&#xD;&#xA;&#xD;&#xA;        Title:{title}{newline}&#xD;&#xA;&#xD;&#xA;        LogMessage:{property(LogMessage)}{newline}"
        name="FlatFile Formatter" />
    </formatters>
    <logFilters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        enabled="true" name="Logging Enabled Filter" />
    </logFilters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Database Trace Listener" />
          <add name="Flat File Trace Listener" />
          <add name="Event Log Trace Listener" />
        </listeners>
      </add>
      <add switchValue="All" name="Error">
        <listeners>
          <add name="Database Trace Listener" />
          <add name="Flat File Trace Listener" />
          <add name="Event Log Trace Listener" />
        </listeners>
      </add>
      <add switchValue="All" name="Warning">
        <listeners>
          <add name="Database Trace Listener" />
          <add name="Flat File Trace Listener" />
          <add name="Event Log Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Event Log Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings" />
    </specialSources>
  </loggingConfiguration>
  <connectionStrings>
    <add name="SQL" connectionString="data source=IPAVAN-D20961;database=RatabaseLogging;uid=TestID06;pwd=TestID06"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true"/>
    <httpRuntime executionTimeout="9999" maxRequestLength="200097151"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="RatabaseLogging.Service">
        <endpoint address="" binding="wsHttpBinding" contract="RatabaseLogging.IService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/RatabaseLogging/Service/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>



 public void Log(string CategoryValue, string SeverityValue, string SourceValue, string TypeValue, string SvcID, string TitleValue, string MessageValue)
        {
            CustomLogEntry lEntry = new CustomLogEntry();

            lEntry.Categories.Add(CategoryValue);
            lEntry.Title = TitleValue;
            lEntry.Message = MessageValue;
            lEntry.SourceValue = SourceValue;
            lEntry.SeverityValue = SeverityValue;
            lEntry.TypeValue = TypeValue;
            lEntry.SvcID = SvcID;
            //lEntry.LogMessage = string.Empty;

            String strGUID = Guid.NewGuid().ToString();

            lEntry.LogEntryID = strGUID;

            Task.Factory.StartNew(() => LogMessageAsync(lEntry));
        }

        #endregion

        #region Asynchronous Logging

        /// <summary>
        /// Asynchronous logging will be done through the inbuilt Enterprise Library method
        /// </summary>
        /// <param name="lEntry"></param>

        static public void LogMessageAsync(CustomLogEntry lEntry)
        {
            LogWriter myLogWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
            myLogWriter.Write(lEntry);
            
        }
The category value that I am forwarding is "Error". When I look into the eventlog...in the "Desccription" field..it is showing everything that
I am forwarding.  But.....the "Category" & "Level" fields in event log are showing "None" and "Information" respectively.  I am not understanding....why event log is not picking up the values that I am forwarding and also that is the requirement.

Thanks
Pavan
May 16, 2012 at 9:40 PM

The LogEntry Severity property is never set in the CustomLogEntry class so the actual Severity of the LogEntry defaults to Information.

To fix this set the Severity in the CustomLogEntry class:

        public string SeverityValue
        {
            get { return this.severityvalue; }
            set 
            { 
                this.severityvalue = value;

                System.Diagnostics.TraceEventType severity;
                if (Enum.TryParse<System.Diagnostics.TraceEventType>(value, out severity))
                {
                    this.Severity = severity;
                }
            }
        }

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

May 17, 2012 at 8:47 PM

Is that "Severity" refers to "Type" in the EventViewer?  Because, after changing the values for Severity to Error,Warning, Information....the "Type" changing accordingly in the EventViewer.  

But, still the Category is "None"....even though I am passing some other value.

May 17, 2012 at 10:04 PM

The Enterprise Library Severity maps to EventLogEntryType for the EventLog.  This can appear under "Event Type" or "Level" depending on the view.

In terms of Category, the Event Log category is not related to the Enterprise Library category so the Event Log category will not display the Enterprise Library category.   This is by design.  (Event Log category is a short whereas Enterprise Library category is a string.)  So, you will not see the Enterprise Library category in the Event Log category.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

May 17, 2012 at 10:26 PM

Got it.  But, EventType value is "Information"...even though I am forwarding the values as "Start", "Stop", "Suspend" and "Verbose".  But, it shows correct for "Error" as "Error", "Warning" as "Warning" and "Information" as "Information".  And also...When I pass "Critical" it is automatically considering it as "Error".

What If I want to send my personalized Level values?

 

And I clearly Understand that Category is not possible to set as per design.  Is there any other way to fullfill this requirement?

Jun 18, 2012 at 3:55 PM

Hi, randy:

I have this problem that on my machine, I can write to event viewer and flat file;

but after I deploy it to web server, I can neither see my log message in event viewer nor

flat file ;  and the log file is not being generated by the program;

what should I do to fix it?  Please help !!!!!!!!!!!

Weeeennni

Jun 30, 2012 at 6:41 AM

@weilinewfl: This sounds like permission issues.  For the Event Log you need to have administrative rights to create the Event Sources.  Usually the event sources will be set up during deployment time.  See EventLog.Source Property.

Similarily, for flat file the application pool user will need permission to create and write to a file.  File permission issues can be troubleshooted using Process Monitor.

I would recommend starting a new discussion if you have further issues.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com