Using log4Net in Windows Control Library

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arulmanoj
    New Member
    • Mar 2009
    • 34

    #1

    Using log4Net in Windows Control Library

    Hi,

    I am using VS 2005 to build a new windows control library using vb.net. Then i am calling this library(DLL) from the ASP.Net web application. Here i want to use the log4Net DLL for writing logs. So where i have to give the configuration details and how to read from the config file.

    Thanks

    Manoj

    Report Post
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Please forgive my ignorance about log4Net. I know a lot of poeple use it, but I haven't checked it out. But I would assume the provider of Log4Net would provide instructions on how to configure/use it. Am I wrong here? Anyone around that uses it? I'm curious about how well they support it. If they don't even provide basic instructions I won't waste my time.

    Comment

    • PRR
      Recognized Expert Contributor
      • Dec 2007
      • 750

      #3
      This article should be helpful... You could also use event logs..or at its simplest a text based log will do...

      Comment

      • Arulmanoj
        New Member
        • Mar 2009
        • 34

        #4
        Using log4Net in Windows Control Library

        Hi DeepBlue,

        This links which you have given is working fine when i use it in a Windows applicaion. But my scenario is as below.

        1. Developed Vb.Net Windows control library.
        2. Calling this DLL in a ASP.Net web application using webform's <OBJECT> tag.
        3. Reading the test.dll.config file using class1.vb vb.net class. This is reading the values from <appsettings> section of the test.dll.config file.

        So now i want to how to read the log4Net configuration from the Test.dll.config file.

        Thanks.

        Manoj

        Comment

        • PRR
          Recognized Expert Contributor
          • Dec 2007
          • 750

          #5
          If i got you correctly you are saying that the assembly has its own config file? ..
          if so you could
          1. Put the settings of assembly in your asp.net app. web.config
          2. Hard code the settings if they are not going to change...
          3. If you can provide "path" you could use,
          Code:
          string path = @"C:\name.config";
                      string section = "appSettings";
          
                      if (File.Exists(path))
                      {
                          System.Configuration.ExeConfigurationFileMap map = new System.Configuration.ExeConfigurationFileMap();
          
                          map.ExeConfigFilename = path;
          
                          System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(map, System.Configuration.ConfigurationUserLevel.None);
          
                          AppSettingsSection appSet = (AppSettingsSection)config.GetSection("appSettings");
          
          
                          
                          foreach (string str in appSet.Settings.AllKeys)
                          {
                              Console.WriteLine(str);
                              Console.Write(appSet.Settings[str].Value);
                          }
          }

          Comment

          • Arulmanoj
            New Member
            • Mar 2009
            • 34

            #6
            Hi DeepBlue,

            Actually i am able to read the Test.dll.config file. But now i want to read the
            log4Net configurations from the test.dll.config file.

            Thanks
            Manoj

            Comment

            • PRR
              Recognized Expert Contributor
              • Dec 2007
              • 750

              #7
              If you go through the code i posted, you will see it does:
              * Reads config file from a particular path..
              If you intent to call your assembly from a web app. and you would like your assembly to read its settings from a particular file then you can use the above code as sample...
              The other way is to put all your settings in web.config file...

              Comment

              Working...