using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using log4net; using Microsoft.Practices.ServiceLocation; namespace Taloyhtio.GeneralApi.IntegrationUtility.Services.Impl { public class SettingsProvider : ISettingsProvider { private ILog logger = ServiceLocator.Current.GetInstance(); public T Get(string key) where T : class { try { return get(key); } catch (Exception x) { this.logger.ErrorFormat(string.Format("{0}\n{1}", x.Message, x.StackTrace)); return null; } } public T? GetVal(string key) where T : struct { try { return get(key); } catch (Exception x) { this.logger.ErrorFormat(string.Format("{0}\n{1}", x.Message, x.StackTrace)); return null; } } private T get(string key) { string val = ConfigurationManager.AppSettings[key]; return (T) Convert.ChangeType(val, typeof (T)); } } }