using System.Net;

namespace Hotline.Logger.Models
{
    public class BaseLogModel
    {
        public BaseLogModel()
        {
            Id = Guid.NewGuid().ToString();
        }

        /// <summary>
        /// 日志id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 时间点
        /// 发起请求时间点
        /// </summary>
        public string RequestTime => DateTime.Now.ToString("yyyy年MM月dd日 hh:mm:ss");

        /// <summary>
        /// 时间戳
        /// </summary>
        public long Timestamp =>
            (long)(DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalMilliseconds;

        /// <summary>
        /// 主机名
        /// 服务所在的机器名
        /// </summary>
        public string Host
        {
            get
            {
                try
                {
                    return Dns.GetHostName();
                }
                catch (Exception)
                {
                    return "获取主机名失败";
                }
            }
        }
    }
}
