• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Problem with Enterprise Library Logging Block

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem with Enterprise Library Logging Block

    The configuration section for Logging cannot be found in the configuration source

    I added a reference to Common and Logging in the Enterprise library and then created a config file using the Enterprise library config gui from the right click menu.

    I have configured :

    Text Formatter
    FlatFile Trace Listener
    Special Sources (All Events, Logging Errors and Warnings, UnProcessed Category - all to use FlatFile Trace Listener)
    Category Sources -> General -> FlatFile Trace Listener

    And I still get the error.

    It compiles ok.

    Code

    LogEntry le = new LogEntry();
    le.Message = message;
    le.Severity = TraceEventType.Verbose;
    le.Priority = 1;
    if (Logger.ShouldLog(le))
    Bold text is where it goes bang.

    Knock first as I might be balancing my chakras.

    #2
    Have you got the required sections in the configSections block of web.config.

    ie.

    <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Loggin g.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=051e068228f92cd6" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />


    Also, your logging configuration should be something like this

    <!--Added For Event Logging Application Configuration-->
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
    <add source="Enterprise Library Logging" formatter="Text Formatter"
    log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLi brary.Logging.Configuration.FormattedEventLogTrace ListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=051e068228f92cd6"
    traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Loggin g.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=051e068228f92cd6"
    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.Loggin g.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=051e068228f92cd6"
    name="Text Formatter" />
    </formatters>
    <categorySources>
    <add switchValue="All" name="General">
    <listeners>
    <add name="Formatted EventLog 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" />
    </listeners>
    </errors>
    </specialSources>
    </loggingConfiguration>


    PS - I'm too lazy to reformat the above xml, so its all yours. Also, depending on which version your using, whether you've put the library into the GAC, etc, then the assembly references to the Enterprise Library may also be different
    Last edited by Weltchy; 15 September 2009, 09:10.

    Comment


      #3
      Originally posted by Weltchy View Post
      Have you got the required sections in the configSections block of web.config.
      It is a win32 app. The app.Config exists and has the required sections

      Originally posted by suityou01's crappy config file
      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
      <configSections>
      <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Loggin g.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </configSections>

      Also, my logging configuration looks something like this

      <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
      defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
      <listeners>
      <add fileName="trace.log" header="----------------------------------------"
      footer="----------------------------------------" formatter=""
      listenerDataType="Microsoft.Practices.EnterpriseLi brary.Logging.Configuration.FlatFileTraceListenerD ata, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Loggin g.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      name="FlatFile 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.Loggin g.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      name="Text Formatter" />
      </formatters>
      <categorySources>
      <add switchValue="All" name="General">
      <listeners>
      <add name="FlatFile TraceListener" />
      </listeners>
      </add>
      </categorySources>
      <specialSources>
      <allEvents switchValue="All" name="All Events">
      <listeners>
      <add name="FlatFile TraceListener" />
      </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
      <listeners>
      <add name="FlatFile TraceListener" />
      </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
      <listeners>
      <add name="FlatFile TraceListener" />
      </listeners>
      </errors>
      </specialSources>
      </loggingConfiguration>
      Knock first as I might be balancing my chakras.

      Comment


        #4
        Hrm, without trawling deep into my own code, don't you also need to set the category property for the LogEntry object?

        Comment


          #5
          I'm so disappointed. Looking at the CUK front page, the title of this thread was Problem with Enterprise... I was hoping for a warp core issue or a problem with the photon torpedoes
          ǝןqqıʍ

          Comment


            #6
            Originally posted by Weltchy View Post
            Hrm, without trawling deep into my own code, don't you also need to set the category property for the LogEntry object?
            The code is lifted from another project and it works. I followed the MSDN article on how to configure EL Logging, and compared each and every node with the project that was working.

            As a last resort I posted here.
            Knock first as I might be balancing my chakras.

            Comment


              #7
              Just checking the obvious, but when you created the config file, was it called app.config and what are the compilation options for it? When you build the project, is the config file being renamed to match [Executable].config? I wonder if for some reason the App.Config file is not being picked up?

              Comment


                #8
                Originally posted by Weltchy View Post
                Just checking the obvious, but when you created the config file, was it called app.config and what are the compilation options for it? When you build the project, is the config file being renamed to match [Executable].config? I wonder if for some reason the App.Config file is not being picked up?
                It's always the obvious that goes wrong.

                Checking now, thanks for your help btw.
                Knock first as I might be balancing my chakras.

                Comment


                  #9
                  Originally posted by Weltchy View Post
                  Just checking the obvious, but when you created the config file, was it called app.config and what are the compilation options for it? When you build the project, is the config file being renamed to match [Executable].config? I wonder if for some reason the App.Config file is not being picked up?
                  MyApp.exe.config
                  Build Action = none
                  It is set to copy to output directory = always

                  Knock first as I might be balancing my chakras.

                  Comment


                    #10
                    Originally posted by Weltchy View Post
                    Just checking the obvious, but when you created the config file, was it called app.config and what are the compilation options for it? When you build the project, is the config file being renamed to match [Executable].config? I wonder if for some reason the App.Config file is not being picked up?
                    Originally posted by suityou01 View Post
                    It's always the obvious that goes wrong.

                    Checking now, thanks for your help btw.
                    Based on your previous posts I am correct in guessing that this is a WPF application? If so Weltchy could be on to something there - by default when you add an application config file to a WPF application it appears to be named app1.config rather than app.config, and needs to be renamed.

                    EDIT: forget all that in light of your last post.
                    Where are we going? And what’s with this hand basket?

                    Comment

                    Working...
                    X