public int CreateLogApi(IDbConnection db, api_log log) { string sql = @"INSERT INTO api_log( action, version, ip_address, game_id, data, message, created_at, status, user_agent, country_code, customer_account_id) VALUES ( @action, @version, @ip_address, @game_id, @data, @message, @created_at, @status, @user_agent, @country_code, @customer_account_id)"; return db.Query<int>(sql, log).FirstOrDefault(); }
public async void LogApi(string version, string action, bool status, string user_agent, int gameId, int customerId, string ip_address, string message, string data) { IPAddress ip; string countryCode = await Task.Factory.StartNew(() => string.Empty); string countryName = string.Empty; if (IPAddress.TryParse(ip_address, out ip)) { if (!ip.GetCountryCode(c => countryCode = c, n => countryName = n)) { countryCode = ip.GetDefaultCountryCode(); } } int? game_id = null; int? user_id = null; if (gameId > 0) { game_id = gameId; } if (customerId > 0) { user_id = customerId; } var log = new api_log { action = action, version = version, ip_address = ip_address, country_code = countryCode, user_agent = user_agent, game_id = game_id, customer_account_id = user_id, data = data, status = status, message = message }; var repo = Repo.Instance; using (var db = repo.OpenConnectionFromPool()) { repo.CreateLogApi(db, log); } }