ApiRequestLog.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.ComponentModel.DataAnnotations;
  2. namespace Domain.Entities.Developers;
  3. /// <summary>
  4. /// 공개 API (/v1/*) 호출 로그.
  5. /// 집계/모니터링/Rate limit 분석용. 1 row = 1 호출.
  6. /// ApplicationID(OAuth2) 또는 PatID(PAT) 중 하나가 채워짐.
  7. /// </summary>
  8. public class ApiRequestLog
  9. {
  10. [Key]
  11. public long ID { get; private set; }
  12. public int? ApplicationID { get; private set; }
  13. public long? PatID { get; private set; }
  14. public string Endpoint { get; private set; } = default!;
  15. public string Method { get; private set; } = default!;
  16. public int StatusCode { get; private set; }
  17. public int ResponseMs { get; private set; }
  18. public string? IpAddress { get; private set; }
  19. public DateTime RequestedAt { get; private set; } = DateTime.UtcNow;
  20. private ApiRequestLog() { }
  21. public static ApiRequestLog Create(
  22. int? applicationID,
  23. long? patID,
  24. string endpoint,
  25. string method,
  26. int statusCode,
  27. int responseMs,
  28. string? ipAddress
  29. )
  30. {
  31. return new ApiRequestLog
  32. {
  33. ApplicationID = applicationID,
  34. PatID = patID,
  35. Endpoint = endpoint,
  36. Method = method,
  37. StatusCode = statusCode,
  38. ResponseMs = responseMs,
  39. IpAddress = ipAddress
  40. };
  41. }
  42. }