/// <summary> /// 将错误日志写入数据库中 /// </summary> /// <param name="logger"></param> /// <param name="message"></param> /// <param name="e"></param> /// <param name="dbName"></param> /// <param name="collection"></param> public static void ErrorWithDb(this LoggerService logger, string message, Exception e, string dbName, string collection) { logger.Error(message, e); var doc = new LogDoc() { Location = logger.DefaultLocation, Message = message, Exception = e, Level = "Error", }; logger.WriteToMogo(doc, dbName, collection); }
/// <summary> /// 将日志内容写入Mongo当中去 /// </summary> public static void WriteToMogo(this LoggerService logger, LogDoc logDoc, string dbName, string collection) { var mongoClient = MongoHelper.GetMongoService(); mongoClient.GetDatabase(dbName).GetCollection <MongoDoc>(collection).InsertOneAsync(logDoc); }