コード例 #1
0
ファイル: NLogEx.cs プロジェクト: chosong/DotnetServer
        public static bool SetConfiguration(string filePath, int retryParentDirectory = 2)
        {
            string path = FileEx.SearchParentDirectory(filePath, retryParentDirectory);

            if (path == null)
            {
                throw new FileNotFoundException(filePath);
            }

            NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(path);

            return(true);
        }
コード例 #2
0
ファイル: JsonAppConfig.cs プロジェクト: chosong/DotnetServer
        public static T Load <T>(string filePath, int retryParentDirectory = 2)
        {
            var    appDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string path         = Path.Combine(appDirectory, filePath);

            path = FileEx.SearchParentDirectory(path, retryParentDirectory);
            if (path == null)
            {
                return(default(T));
            }

            string json = File.ReadAllText(path);

            if (json == null)
            {
                throw new FileNotFoundException(filePath);
            }

            return(JsonConvert.DeserializeObject <T>(json));
        }