ConfigAppSettings.cs 1.4 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Threading;
using System.Xml;
using System.Windows.Forms;
using log4net;

namespace OnlineStore.Common
{
    public class ConfigAppSettings
    {
        public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private static int seq = 1;

        public static int nextSeq()
        {
            if (seq.Equals(Int32.MaxValue))
            {
                LOGGER.Info("seq当前值:" + seq + ",重置seq=0");
                seq = 0;
            }
            Interlocked.Increment(ref seq);
            return seq;
        }

        public static string GetValue(string key, string val = "")
        {
            return ConfigHelper.Config.Get(key, val);
        }
        public static int GetIntValue(string key, int val = 0)
        {
            return ConfigHelper.Config.Get(key, val);
        }
        public static void SaveValue(string key, int value)
        {
            try
            {
                ConfigHelper.Config.Set(key, value);
            }
            catch (Exception ex)
            {
                LogUtil.error(LOGGER, "SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + "," + ex.StackTrace);
            }
        }
    }
}