Logging in Enterprise Library

Topics: Enterprise Library Core, Logging Application Block
Apr 15, 2011 at 4:04 AM

Hi, 

   I am creating some sample applicaiton for Enterprise Logging and i am new to this topic, when i click "Button" i have following proplem("The configuration section for Logging cannot be found in the configuration source."), i created Web.config file also(Add New Items->General-> Selecte Application Configuration File->Changes App1.config as Web.config) in my projecte, eventhough i am gettting this problem.Can you correct my problem, here i attached my sample code. Let me know, if you have any doubt, I feel this is a correct forum to discuss this issue, if am wrong please tell me, where i need to post

 

Window.Xaml

<Window x:Class="LoggingEvent1.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="MainWindow" Height="350" Width="525">
 <Grid>
  <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="120,76,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
 </Grid>
</Window>

Window.Xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.ObjectBuilder2;


namespace LoggingEvent1
{
 /// <summary>
 /// Interaction logic for MainWindow.xaml
 /// </summary>
 public partial class MainWindow : Window
 {
  public MainWindow()
  {
   InitializeComponent();
  }

  private void button1_Click(object sender, RoutedEventArgs e)
  {
   LogEntry logEntry = new LogEntry();
   logEntry.EventId = 100;
   logEntry.Priority = 2;
   logEntry.Message = "Informational message";
   logEntry.Categories.Add("Trace");
   logEntry.Categories.Add("UI Events");   

   Logger.Write(logEntry);



  }
 }
}


Apr 15, 2011 at 4:37 AM

This is my Web.Config file.

Web.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
Apr 15, 2011 at 5:07 AM

Is this a wpf application?  If yes, your config file should be named as app.config. 

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 15, 2011 at 8:13 AM

Yes, this is Wpf Application

Apr 15, 2011 at 8:38 AM

Renaming your config file to app.config should fix the problem.  This is the name of the config file which the CLR searches for and at runtime, creates a copy of it in the project's output folder with the filename {applicationName}.exe.config

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 16, 2011 at 4:37 PM

Yeah,

   I got output to this problem, thanks for your quick reply