7 Replies - 870 Views - Last Post: 21 February 2013 - 04:57 PM Rate Topic: -----

#1 alentor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-February 13

app.config console

Posted 21 February 2013 - 02:46 PM

Hello I'm trying to use app.config in a simple console application, but my code isn't working. Can please someone check my code?

app.config
<configuration>
  <appSettings>
    <add key="level" value="5"></add>
  </appSettings>
</configuration>



console1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string level = System.Configuration.ConfigurationManager.AppSettings["level"];
            Console.WriteLine("Logger level: " + level);
            Console.ReadLine();
        }
    }
}




Is This A Good Question/Topic? 0
  • +

Replies To: app.config console

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6538
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: app.config console

Posted 21 February 2013 - 02:54 PM

These tutorials should help


Was This Post Helpful? 1
  • +
  • -

#3 alentor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-February 13

Re: app.config console

Posted 21 February 2013 - 02:56 PM

View PosttlhIn`toq, on 21 February 2013 - 02:54 PM, said:




Don't think this is what gonna help me. Thank you!
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: app.config console

Posted 21 February 2013 - 03:01 PM

Quote

but my code isn't working


So...what is it doing? We need to know what errors you're getting, if any, or what behavior you're seeing, if it differs from what you expect.

Why "It doesn't work!" isn't good enough.
Was This Post Helpful? 0
  • +
  • -

#5 h4nnib4l   User is offline

  • The Noid
  • member icon

Reputation: 1686
  • View blog
  • Posts: 2,335
  • Joined: 24-August 11

Re: app.config console

Posted 21 February 2013 - 03:34 PM

View Postalentor, on 21 February 2013 - 03:56 PM, said:

View PosttlhIn`toq, on 21 February 2013 - 02:54 PM, said:




Don't think this is what gonna help me. Thank you!


You replied 2 minutes after he posted them, so unless you're the world's fastest reader, I doubt you even bothered to look into them at all. When an expert gives you links to tutorials that he (or others) have created in response to a question, there's a pretty good chance that what you need (or something to get you on the right track at least) is in there. It's a safe bet that unless you're asking something really unusual, then it's probably been asked and answered before. But it that's how you treat efforts at helping you, then you'll probably find it difficult to get more help.
Was This Post Helpful? 1
  • +
  • -

#6 alentor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-February 13

Re: app.config console

Posted 21 February 2013 - 03:49 PM

View PostCurtis Rutland, on 21 February 2013 - 03:01 PM, said:

Quote

but my code isn't working


So...what is it doing? We need to know what errors you're getting, if any, or what behavior you're seeing, if it differs from what you expect.

Why "It doesn't work!" isn't good enough.



The application isn't working and at the same time I don't get any type of error.


Posted Image
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: app.config console

Posted 21 February 2013 - 03:57 PM

Well, the first thing that springs to mind is that the key you show in the config file in your first post is "level", and the key you're attempting to access in your screenshot is "LoggerLevel". Make sure you're actually using the same key in both locations.

The only other thing I can tell you to do is put a breakpoint and use the Watch palette to determine what the actual values that the AppSettings property contains.
Was This Post Helpful? 0
  • +
  • -

#8 alentor   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-February 13

Re: app.config console

Posted 21 February 2013 - 04:57 PM

View PosttlhIn`toq, on 21 February 2013 - 02:54 PM, said:



Thank you! I apologize for my first post! This really helped me to understand what is OO! I thought I knew what it is, but after reading your explanation/tutorial I understood it even more! Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1