Enyim.Caching调用GetValueOrCreateAsync,出现异常

2019-02-21 19:58发布

问题:

EnyimMemcachedCore 2.1.8
异常信息:
System.AggregateException: An error occurred while writing to logger(s). (Input/output error) ---> System.IO.IOException: Input/output error
at System.ConsolePal.Write(SafeFileHandle fd, Byte* bufPtr, Int32 count)
at System.ConsolePal.Write(SafeFileHandle fd, Byte[] buffer, Int32 offset, Int32 count)
at System.ConsolePal.UnixConsoleStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(String value)
at System.IO.SyncTextWriter.Write(String value)
at System.Console.Write(String value)
at Microsoft.Extensions.Logging.Console.ConsoleLogger.AnsiSystemConsole.Write(String message)
at Microsoft.Extensions.Logging.Console.Internal.AnsiLogConsole.Flush()
at Microsoft.Extensions.Logging.Console.Internal.ConsoleLoggerProcessor.WriteMessage(LogMessageEntry message)
at Microsoft.Extensions.Logging.Console.Internal.ConsoleLoggerProcessor.EnqueueMessage(LogMessageEntry message)
at Microsoft.Extensions.Logging.Console.ConsoleLogger.WriteMessage(LogLevel logLevel, String logName, Int32 eventId, String message, Exception exception)
at Microsoft.Extensions.Logging.Console.ConsoleLogger.LogTState
at Microsoft.Extensions.Logging.Logger.LogTState
--- End of inner exception stack trace ---
at Microsoft.Extensions.Logging.Logger.LogTState
at Microsoft.Extensions.Logging.Logger1.Microsoft.Extensions.Logging.ILogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func3 formatter)
at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)
at Microsoft.Extensions.Logging.LoggerExtensions.LogError(ILogger logger, String message, Object[] args)
at Enyim.Caching.Memcached.MemcachedNode.Acquire()
at Enyim.Caching.Memcached.MemcachedNode.ExecuteOperationAsync(IOperation op)
at Enyim.Caching.Memcached.MemcachedNode.Enyim.Caching.Memcached.IMemcachedNode.ExecuteAsync(IOperation op)
at Enyim.Caching.MemcachedClient.GetAsyncT
---> (Inner Exception #0) System.IO.IOException: Input/output error
at System.ConsolePal.Write(SafeFileHandle fd, Byte* bufPtr, Int32 count)
at System.ConsolePal.Write(SafeFileHandle fd, Byte[] buffer, Int32 offset, Int32 count)
at System.ConsolePal.UnixConsoleStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(String value)
at System.IO.SyncTextWriter.Write(String value)
at System.Console.Write(String value)
at Microsoft.Extensions.Logging.Console.ConsoleLogger.AnsiSystemConsole.Write(String message)
at Microsoft.Extensions.Logging.Console.Internal.AnsiLogConsole.Flush()
at Microsoft.Extensions.Logging.Console.Internal.ConsoleLoggerProcessor.WriteMessage(LogMessageEntry message)
at Microsoft.Extensions.Logging.Console.Internal.ConsoleLoggerProcessor.EnqueueMessage(LogMessageEntry message)
at Microsoft.Extensions.Logging.Console.ConsoleLogger.WriteMessage(LogLevel logLevel, String logName, Int32 eventId, String message, Exception exception)
at Microsoft.Extensions.Logging.Console.ConsoleLogger.LogTState
at Microsoft.Extensions.Logging.Logger.LogTState<---

对Enyim APi的封装代码1:
/// <summary>
/// 获取缓存对象
/// </summary>
/// <typeparam name="T">缓存的对象类型</typeparam>
/// <param name="key">缓存key</param>
/// <param name="generator">缓存对象的委托</param>
/// <param name="expire">过期时间</param>
/// <returns></returns>
public static Task<T> Get<T>(string key, Func<Task<T>> generator, TimeSpan? expire = null)
{
return memcachedClient.GetValueOrCreateAsync(key, GetSeconds(expire), generator);
}
调用代码2:
public async Task<List<UserCreditLevelConfigCacheDTO>> GetListCache() {
var systemParamCacheList = await MemcachedHelper.Get(MemcachedConstConfig.CacheKey_UserCreditLevelConfigList,
() => {
//todo
}, MemcachedConstConfig.DefaultExpireTime);
return systemParamCacheList.MapToList<UserCreditLevelConfigCacheDTO>();
}
调用代码3:
var creditLevelItemList = await _userCreditLevelConfigService.GetListCache();

代码片段3中,调用了代码2,代码2中调用了代码1。

回答1:

这个问题与 EnyimMemcachedCore 无关,是你的环境无法写控制台日志