首页 新闻 会员 周边 捐助

Enyim.Caching调用GetValueOrCreateAsync,出现异常

0
悬赏园豆:20 [已解决问题] 解决于 2019-02-21 20:34

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。

Code_Song的主页 Code_Song | 初学一级 | 园豆:51
提问于:2019-02-19 19:51

能看下有关使用EnyimMemcachedCore的代码吗?

hellotim 5年前

@hellotim: ok。我再完善一下问题详情

Code_Song 5年前

@hellotim: 单步的调试都没有什么问题,但是我在收集的错误日志中,发现有这样的异常错误。不知所以

Code_Song 5年前
< >
分享
最佳答案
0

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

收获园豆:20
dudu | 高人七级 |园豆:29732 | 2019-02-19 20:11

dudu,我的项目类型是.netcore api。如何修复支持console log呢?

Code_Song | 园豆:51 (初学一级) | 2019-02-19 20:13

我再看看,目前我的项目部署环境是windows

Code_Song | 园豆:51 (初学一级) | 2019-02-19 20:14

@Code_Song: 程序运行在什么操作系统上?是什么方式运行的(supervisor, docker...)?日志是如何配置的?为什么不使用 Serilog 而是使用控制台日志?

dudu | 园豆:29732 (高人七级) | 2019-02-19 20:16

Windows 的话,控制台日志会被重定向到文件中,建议检查一下 logs 文件夹的权限

dudu | 园豆:29732 (高人七级) | 2019-02-19 20:18

@dudu: 程序运行在windows2008(测试环境),自宿主方式运行。项目中的日志方式是用的Nlog,并没有去配置成控制台日志,为什么会去写入控制台呢。

Code_Song | 园豆:51 (初学一级) | 2019-02-19 20:20

@dudu: 项目中对日志配置了收集到mysql数据库

Code_Song | 园豆:51 (初学一级) | 2019-02-19 20:21

@Code_Song: 在 web.config 中将 stdoutLogEnabled 设置为 false

dudu | 园豆:29732 (高人七级) | 2019-02-19 20:34

@dudu: 现在.netcore类型的,没有web.config文件呢。
刚刚发现了另外的错误,帮助看看
System.ArgumentOutOfRangeException: Unexpected BsonType value: 0
Parameter name: type
at Newtonsoft.Json.Bson.BsonDataReader.ReadType(BsonType type)
at Newtonsoft.Json.Bson.BsonDataReader.ReadNormal()
at Newtonsoft.Json.Bson.BsonDataReader.Read()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.DeserializeT
at Enyim.Caching.Memcached.DefaultTranscoder.DeserializeT
at Enyim.Caching.MemcachedClient.BuildGetCommandResultT
at Enyim.Caching.MemcachedClient.GetAsyncT

Code_Song | 园豆:51 (初学一级) | 2019-02-19 20:37

@Code_Song: 将 EnyimMemcachedCore 升级到最新版可解决这个问题

dudu | 园豆:29732 (高人七级) | 2019-02-19 20:40

@dudu: 好的

Code_Song | 园豆:51 (初学一级) | 2019-02-19 20:41

@dudu: 最新版本的Nuget包,可以和memache1.5版本一起工作吗

Code_Song | 园豆:51 (初学一级) | 2019-02-19 21:32

@Code_Song: 可以,那个问题已经修复

dudu | 园豆:29732 (高人七级) | 2019-02-19 21:38

@dudu: ok,谢谢

Code_Song | 园豆:51 (初学一级) | 2019-02-19 21:39

@dudu:
Enyim.Caching.MemcachedClient|GetAsync("AdminMenuList") 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 Enyim.Caching.Memcached.MemcachedNode.InternalPoolImpl.MarkAsDead()
at Enyim.Caching.Memcached.MemcachedNode.InternalPoolImpl.ReleaseSocket(PooledSocket socket)
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<---

Code_Song | 园豆:51 (初学一级) | 2019-02-24 16:24

@dudu: 这个是我把应用Enyim Memcached包的项目发布到CentOS服务器上之后,看到的错误日志
env.ConfigureNLog("NLog.config");
app.UseEnyimMemcached();
项目的配置是这样的,参考的Demo来的。

Code_Song | 园豆:51 (初学一级) | 2019-02-24 16:26

@Code_Song: 试试禁用控制台日志

dudu | 园豆:29732 (高人七级) | 2019-02-24 16:36

@dudu: 我看Nlog.Config里面,并没有配置Console类型的日志输出呢
为什么输出到控制台,会影响Enyim.Memcache包的程序?

<target xsi:type="File" name="allfile" fileName="${basedir}/logs/nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<target xsi:type="File" name="ownFile-web" fileName="${basedir}/logs/nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
<!--收集异常日志到mysql数据库-->
<target xsi:type="Database" name="database" dbProvider="MySql.Data.MySqlClient.MySqlConnection, MySql.Data"

Code_Song | 园豆:51 (初学一级) | 2019-02-24 16:43

@dudu: 谢谢dudu,我再观察一下看看,这个异常很怪异。再有问题,我把调用和发生的场景提到git上

Code_Song | 园豆:51 (初学一级) | 2019-02-24 17:46

@Code_Song: 控制台日志是默认就启用的,可以在 Program.cs 中添加下面的代码代码移除控制台日志

.ConfigureLogging((context, logging) =>
{ 
    logging.ClearProviders();
});
dudu | 园豆:29732 (高人七级) | 2019-02-24 18:53

@dudu: 好的

Code_Song | 园豆:51 (初学一级) | 2019-02-24 21:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册