diff --git a/Cache/OSS.Tools.Cache/CacheHelper.cs b/Cache/OSS.Tools.Cache/CacheHelper.cs index 2d95545..7e3b0ea 100644 --- a/Cache/OSS.Tools.Cache/CacheHelper.cs +++ b/Cache/OSS.Tools.Cache/CacheHelper.cs @@ -38,11 +38,8 @@ namespace OSS.Tools.Cache /// /// /// - public static IToolCache GetCache(string sourceName= "default") + public static IToolCache GetCache(string sourceName= "") { - if (string.IsNullOrEmpty(sourceName)) - sourceName = "default"; - if (SourceFormat != null) sourceName = SourceFormat.Invoke(sourceName); @@ -62,7 +59,7 @@ namespace OSS.Tools.Cache /// 滚动过期时长,访问后自动延长 /// 来源名称 /// 是否添加成功 - public static Task SetAsync(string key, T obj, TimeSpan slidingExpiration, string sourceName = "default") + public static Task SetAsync(string key, T obj, TimeSpan slidingExpiration, string sourceName = "") { return SetAsync(key, obj,new CacheTimeOptions(){sliding_expiration = slidingExpiration }, sourceName); } @@ -76,7 +73,7 @@ namespace OSS.Tools.Cache /// 固定过期时长,设置后到时过期 /// 来源名称 /// 是否添加成功 - public static Task SetAbsoluteAsync(string key, T obj, TimeSpan absoluteExpiration, string sourceName = "default") + public static Task SetAbsoluteAsync(string key, T obj, TimeSpan absoluteExpiration, string sourceName = "") { return SetAsync(key, obj, new CacheTimeOptions(){absolute_expiration_relative_to_now = absoluteExpiration}, sourceName); } @@ -90,7 +87,7 @@ namespace OSS.Tools.Cache /// 缓存过期时间选项 /// /// - public static Task SetAsync(string key, T obj, CacheTimeOptions opt, string sourceName = "default") + public static Task SetAsync(string key, T obj, CacheTimeOptions opt, string sourceName = "") { return GetCache(sourceName).SetAsync(key, obj, opt); } @@ -106,7 +103,7 @@ namespace OSS.Tools.Cache /// key /// 来源名称 /// 获取指定key对应的值 - public static Task GetAsync(string key, string sourceName = "default") + public static Task GetAsync(string key, string sourceName = "") { return GetCache(sourceName).GetAsync(key); } @@ -127,7 +124,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// public static Task GetOrSetAsync(string cacheKey, Func> getFunc, - TimeSpan slidingExpiration, int hitProtectedSeconds = 10, string sourceName = "default") + TimeSpan slidingExpiration, int hitProtectedSeconds = 10, string sourceName = "") { return GetOrSetAsync(cacheKey, getFunc, new CacheTimeOptions() { sliding_expiration = slidingExpiration }, null, hitProtectedSeconds, sourceName); } @@ -145,7 +142,7 @@ namespace OSS.Tools.Cache /// public static Task GetOrSetAsync(string cacheKey, Func> getFunc,TimeSpan slidingExpiration, Func beforeSettingChecker, int hitProtectedSeconds = 10, - string sourceName = "default") + string sourceName = "") { return GetOrSetAsync(cacheKey, getFunc,new CacheTimeOptions(){sliding_expiration = slidingExpiration}, beforeSettingChecker, hitProtectedSeconds, sourceName); } @@ -161,7 +158,7 @@ namespace OSS.Tools.Cache /// 缓存击穿保护秒数,默认值10。 /// 来源名称 /// - public static Task GetOrSetAbsoluteAsync(string cacheKey, Func> getFunc, TimeSpan absoluteExpiration, int hitProtectedSeconds = 10, string sourceName = "default") + public static Task GetOrSetAbsoluteAsync(string cacheKey, Func> getFunc, TimeSpan absoluteExpiration, int hitProtectedSeconds = 10, string sourceName = "") { return GetOrSetAsync(cacheKey, getFunc, new CacheTimeOptions() { absolute_expiration_relative_to_now = absoluteExpiration }, null , hitProtectedSeconds, sourceName); @@ -180,7 +177,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// public static Task GetOrSetAbsoluteAsync(string cacheKey, Func> getFunc,TimeSpan absoluteExpiration, - Func beforeSettingChecker, int hitProtectedSeconds = 10,string sourceName = "default") + Func beforeSettingChecker, int hitProtectedSeconds = 10,string sourceName = "") { return GetOrSetAsync(cacheKey, getFunc, new CacheTimeOptions(){absolute_expiration_relative_to_now = absoluteExpiration}, beforeSettingChecker, hitProtectedSeconds, sourceName); } @@ -199,7 +196,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// public static async Task GetOrSetAsync(string cacheKey, Func> getFunc, CacheTimeOptions cacheTimeOpt, - Func beforeSettingChecker = null, int hitProtectedSeconds = 10, string sourceName = "default") + Func beforeSettingChecker = null, int hitProtectedSeconds = 10, string sourceName = "") { if (getFunc == null) throw new ArgumentNullException("获取原始数据方法(getFunc)不能为空!"); @@ -251,7 +248,7 @@ namespace OSS.Tools.Cache /// /// 来源名称 /// 是否成功 - public static Task RemoveAsync(string key, string sourceName = "default") + public static Task RemoveAsync(string key, string sourceName = "") { return GetCache(sourceName).RemoveAsync(key); } @@ -262,13 +259,11 @@ namespace OSS.Tools.Cache /// /// 来源名称 /// 是否成功 - public static Task RemoveAsync(string[] keys, string sourceName = "default") + public static Task RemoveAsync(string[] keys, string sourceName = "") { return GetCache(sourceName).RemoveAsync(keys); } - - #region 过时方法 /// @@ -279,14 +274,14 @@ namespace OSS.Tools.Cache /// 来源名称 /// 获取指定key对应的值 [Obsolete("请使用 GetAsync")] - public static T Get(string key, string sourceName = "default") + public static T Get(string key, string sourceName = "") { return GetAsync(key, sourceName).Result; } [Obsolete("请使用 RemoveAsync")] - public static bool Remove(string key, string sourceName = "default") + public static bool Remove(string key, string sourceName = "") { return RemoveAsync(key,sourceName).Result; } @@ -301,7 +296,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// 是否添加成功 [Obsolete("请使用 SetAsync")] - public static bool Set(string key, T obj, TimeSpan slidingExpiration, string sourceName = "default") + public static bool Set(string key, T obj, TimeSpan slidingExpiration, string sourceName = "") { return SetAsync(key, obj, slidingExpiration, sourceName).Result; } @@ -316,7 +311,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// 是否添加成功 [Obsolete("请使用 SetAbsoluteAsync")] - public static bool Set(string key, T obj, DateTime absoluteExpiration, string sourceName = "default") + public static bool Set(string key, T obj, DateTime absoluteExpiration, string sourceName = "") { return SetAbsoluteAsync(key, obj, TimeSpan.FromTicks((absoluteExpiration - DateTime.Now).Ticks), sourceName).Result; } diff --git a/Cache/OSS.Tools.Cache/Extension/FuncCacheExtension.cs b/Cache/OSS.Tools.Cache/Extension/FuncCacheExtension.cs index 0e5c5c0..d8ca7ba 100644 --- a/Cache/OSS.Tools.Cache/Extension/FuncCacheExtension.cs +++ b/Cache/OSS.Tools.Cache/Extension/FuncCacheExtension.cs @@ -21,7 +21,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// public static Task WithCacheAsync(this Func> getFunc, string cacheKey, - TimeSpan slidingExpiration, int hitProtectedSeconds = 10, string sourceName = "default") + TimeSpan slidingExpiration, int hitProtectedSeconds = 10, string sourceName = "") { return CacheHelper.GetOrSetAsync(cacheKey, getFunc, new CacheTimeOptions() { sliding_expiration = slidingExpiration }, null, hitProtectedSeconds, sourceName); } @@ -39,7 +39,7 @@ namespace OSS.Tools.Cache /// public static Task WithCacheAsync(this Func> getFunc, string cacheKey, TimeSpan slidingExpiration, Func beforeSettingChecker, int hitProtectedSeconds = 10, - string sourceName = "default") + string sourceName = "") { return CacheHelper.GetOrSetAsync(cacheKey, getFunc, new CacheTimeOptions() { sliding_expiration = slidingExpiration }, beforeSettingChecker, hitProtectedSeconds, sourceName); } @@ -55,7 +55,7 @@ namespace OSS.Tools.Cache /// 缓存击穿保护秒数,默认值10。 /// 来源名称 /// - public static Task WithAbsoluteCacheAsync(this Func> getFunc, string cacheKey, TimeSpan absoluteExpiration, int hitProtectedSeconds = 10, string sourceName = "default") + public static Task WithAbsoluteCacheAsync(this Func> getFunc, string cacheKey, TimeSpan absoluteExpiration, int hitProtectedSeconds = 10, string sourceName = "") { return CacheHelper.GetOrSetAsync(cacheKey, getFunc, new CacheTimeOptions() { absolute_expiration_relative_to_now = absoluteExpiration }, null , hitProtectedSeconds, sourceName); @@ -74,7 +74,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// public static Task WithAbsoluteCacheAsync(this Func> getFunc, string cacheKey, TimeSpan absoluteExpiration, - Func beforeSettingChecker, int hitProtectedSeconds = 10, string sourceName = "default") + Func beforeSettingChecker, int hitProtectedSeconds = 10, string sourceName = "") { return CacheHelper.GetOrSetAsync(cacheKey, getFunc, new CacheTimeOptions() @@ -98,7 +98,7 @@ namespace OSS.Tools.Cache /// 来源名称 /// public static Task WithCacheAsync(this Func> getFunc, string cacheKey, CacheTimeOptions cacheTimeOpt, - Func beforeSettingChecker = null, int hitProtectedSeconds = 10, string sourceName = "default") + Func beforeSettingChecker = null, int hitProtectedSeconds = 10, string sourceName = "") { return CacheHelper.GetOrSetAsync(cacheKey, getFunc, cacheTimeOpt, beforeSettingChecker, hitProtectedSeconds, sourceName); } diff --git a/Cache/OSS.Tools.Cache/OSS.Tools.Cache.csproj b/Cache/OSS.Tools.Cache/OSS.Tools.Cache.csproj index 1bd2f26..f3ae39a 100644 --- a/Cache/OSS.Tools.Cache/OSS.Tools.Cache.csproj +++ b/Cache/OSS.Tools.Cache/OSS.Tools.Cache.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 2.2 + 2.2.1 http://img1.osscore.cn/static/oss_net.png https://github.com/KevinWG/OSS.Tools diff --git a/Config/OSS.Tools.DirConfig/DefaultToolDirConfig.cs b/Config/OSS.Tools.DirConfig/DefaultToolDirConfig.cs index c2ee976..50dde8e 100644 --- a/Config/OSS.Tools.DirConfig/DefaultToolDirConfig.cs +++ b/Config/OSS.Tools.DirConfig/DefaultToolDirConfig.cs @@ -51,7 +51,7 @@ namespace OSS.Tools.DirConfig private const string _folderName = "Configs"; /// - public Task SetDirConfig(string key, TConfig dirConfig, string sourceName) where TConfig : class, new() + public Task SetDirConfig(string key, TConfig dirConfig, string sourceName) { if (string.IsNullOrEmpty(key)) throw new ArgumentNullException(nameof(key), "配置键值不能为空!"); @@ -81,7 +81,7 @@ namespace OSS.Tools.DirConfig /// - public Task GetDirConfig(string key, string sourceName) where TConfig : class, new() + public Task GetDirConfig(string key, string sourceName) { if (string.IsNullOrEmpty(key)) diff --git a/Config/OSS.Tools.DirConfig/DirConfigHelper.cs b/Config/OSS.Tools.DirConfig/DirConfigHelper.cs index 8f6ad86..77f95e5 100644 --- a/Config/OSS.Tools.DirConfig/DirConfigHelper.cs +++ b/Config/OSS.Tools.DirConfig/DirConfigHelper.cs @@ -44,9 +44,6 @@ namespace OSS.Tools.DirConfig /// private static IToolDirConfig GetDirConfig(string sourceName) { - if (string.IsNullOrEmpty(sourceName)) - sourceName = "default"; - if (SourceFormat != null) sourceName = SourceFormat.Invoke(sourceName); @@ -63,7 +60,7 @@ namespace OSS.Tools.DirConfig /// /// public static Task SetDirConfig(string key, TConfig dirConfig, - string sourceName = "default") where TConfig : class, new() + string sourceName = "") where TConfig : class, new() { return GetDirConfig(sourceName).SetDirConfig(key, dirConfig,sourceName); } @@ -76,7 +73,7 @@ namespace OSS.Tools.DirConfig /// /// 来源名称 /// - public static Task GetDirConfig(string key, string sourceName = "default") + public static Task GetDirConfig(string key, string sourceName = "") where TConfig : class, new() { return GetDirConfig(sourceName).GetDirConfig(key, sourceName); @@ -88,7 +85,7 @@ namespace OSS.Tools.DirConfig /// /// 来源名称 /// - public static Task RemoveDirConfig(string key, string sourceName = "default") + public static Task RemoveDirConfig(string key, string sourceName = "") { return GetDirConfig(sourceName).RemoveDirConfig(key, sourceName); } diff --git a/Config/OSS.Tools.DirConfig/IToolDirConfig.cs b/Config/OSS.Tools.DirConfig/IToolDirConfig.cs index e789b24..eb31e2f 100644 --- a/Config/OSS.Tools.DirConfig/IToolDirConfig.cs +++ b/Config/OSS.Tools.DirConfig/IToolDirConfig.cs @@ -29,7 +29,7 @@ namespace OSS.Tools.DirConfig /// 来源名称 /// 配置信息类型 /// - Task SetDirConfig(string key, TConfig dirConfig, string sourceName) where TConfig : class ,new(); + Task SetDirConfig(string key, TConfig dirConfig, string sourceName); /// @@ -39,7 +39,7 @@ namespace OSS.Tools.DirConfig /// 来源名称 /// 配置信息类型 /// - Task GetDirConfig(string key, string sourceName) where TConfig : class ,new(); + Task GetDirConfig(string key, string sourceName); /// /// 移除配置信息 diff --git a/Config/OSS.Tools.DirConfig/OSS.Tools.DirConfig.csproj b/Config/OSS.Tools.DirConfig/OSS.Tools.DirConfig.csproj index 33bd3e2..30992b7 100644 --- a/Config/OSS.Tools.DirConfig/OSS.Tools.DirConfig.csproj +++ b/Config/OSS.Tools.DirConfig/OSS.Tools.DirConfig.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 2.1 + 2.1.1 优化扩展 http://img1.osscore.cn/static/oss_net.png https://github.com/KevinWG/OSS.Tools diff --git a/Log/OSS.Tools.Log/DefaultToolLog.cs b/Log/OSS.Tools.Log/DefaultToolLog.cs index 6ff651b..9cf17c0 100644 --- a/Log/OSS.Tools.Log/DefaultToolLog.cs +++ b/Log/OSS.Tools.Log/DefaultToolLog.cs @@ -38,8 +38,10 @@ namespace OSS.Tools.Log private string getLogFilePath(string module, LogLevelEnum level) { - var date = DateTime.Now; - var dirPath = Path.Combine(_logBaseDirPath, string.Concat(module, "_", level), + var date = DateTime.Now; + var moduleName = string.IsNullOrEmpty(module) ? "default" : module; + + var dirPath = Path.Combine(_logBaseDirPath, string.Concat(moduleName, "_", level), DateTime.Now.ToString("yyyyMM")); //string.Format(@"{0}\{1}\{2}\",_logBaseDirPath, module, level); if (!Directory.Exists(dirPath)) diff --git a/Log/OSS.Tools.Log/LogHelper.cs b/Log/OSS.Tools.Log/LogHelper.cs index faf420a..caad913 100644 --- a/Log/OSS.Tools.Log/LogHelper.cs +++ b/Log/OSS.Tools.Log/LogHelper.cs @@ -27,7 +27,7 @@ namespace OSS.Tools.Log /// - /// 日志来源提供者 + /// 日志工具提供者 /// public static Func LogToolProvider { get; set; } @@ -44,9 +44,6 @@ namespace OSS.Tools.Log /// public static IToolLog GetLogWrite(string logModule) { - if (string.IsNullOrEmpty(logModule)) - logModule = "default"; - return LogToolProvider?.Invoke(logModule) ?? DefaultLogTool; } @@ -56,7 +53,7 @@ namespace OSS.Tools.Log /// 日志信息 /// 关键值 /// 来源名称 - public static string Info(object msg, string msgKey = null, string sourceName = "default") + public static string Info(object msg, string msgKey = null, string sourceName = "") { return Log(new LogInfo(LogLevelEnum.Info, msg, msgKey, sourceName)); } @@ -67,7 +64,7 @@ namespace OSS.Tools.Log /// 日志信息 /// 关键值 /// 来源名称 - public static string Warning(object msg, string msgKey = null, string sourceName = "default") + public static string Warning(object msg, string msgKey = null, string sourceName = "") { return Log(new LogInfo(LogLevelEnum.Warning, msg, msgKey, sourceName)); } @@ -78,7 +75,7 @@ namespace OSS.Tools.Log /// 日志信息 /// 关键值 /// 来源名称 - public static string Error(object msg, string msgKey = null, string sourceName = "default") + public static string Error(object msg, string msgKey = null, string sourceName = "") { return Log(new LogInfo(LogLevelEnum.Error, msg, msgKey, sourceName)); } @@ -89,7 +86,7 @@ namespace OSS.Tools.Log /// 日志信息 /// 关键值 /// 来源名称 - public static string Trace(object msg, string msgKey = null, string sourceName = "default") + public static string Trace(object msg, string msgKey = null, string sourceName = "") { return Log(new LogInfo(LogLevelEnum.Trace, msg, msgKey, sourceName)); } @@ -103,7 +100,7 @@ namespace OSS.Tools.Log try { if (string.IsNullOrEmpty(info.source_name)) - info.source_name = "default"; + info.source_name = ""; LogFormat?.Invoke(info); GetLogWrite(info.source_name)?.WriteLogAsync(info); diff --git a/Log/OSS.Tools.Log/LogInfo.cs b/Log/OSS.Tools.Log/LogInfo.cs index a119fba..8d23a58 100644 --- a/Log/OSS.Tools.Log/LogInfo.cs +++ b/Log/OSS.Tools.Log/LogInfo.cs @@ -59,7 +59,7 @@ namespace OSS.Tools.Log /// /// /// - internal LogInfo(LogLevelEnum loglevel, object logMsg, string msgKey = null, string sourceName = "default") + internal LogInfo(LogLevelEnum loglevel, object logMsg, string msgKey = null, string sourceName = "") { level = loglevel; source_name = sourceName; diff --git a/Log/OSS.Tools.Log/OSS.Tools.Log.csproj b/Log/OSS.Tools.Log/OSS.Tools.Log.csproj index 093fbbd..09c711d 100644 --- a/Log/OSS.Tools.Log/OSS.Tools.Log.csproj +++ b/Log/OSS.Tools.Log/OSS.Tools.Log.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 1.2.2 + 1.2.3 修改属性名称 https://github.com/KevinWG/OSS.Tools https://github.com/KevinWG/OSS.Tools