Esempio n. 1
0
        public void Log(LogValue value)
        {
            var text = $"<html><body><style>h3{{background-color:#eef;}}</style><h3>{value.Time:yyyy-MM-dd HH:mm:ss}</h3>";

            text += $"<h3>Machine: {value.Machine} / Action: {value.Action}</h3>";
            if (value.Class != null)
            {
                text += $"<h3>Class {value.Class} / Method {value.Method}</h3>";
            }
            if (value.Note != null)
            {
                text += $"<h3>Note</h3><p>{value.Note}</p>";
            }
            if (value.Key != null)
            {
                text += $"<h3>Key {value.Key}  Value {value.Value}</h3>";
            }
            if (value.JsonObj != null)
            {
                text += $"<h3>{value.TypeObj}</h3><code>{value.JsonObj}</code>";
            }
            if (value.Message != null)
            {
                text += $"<h3>{value.Message}</h3>";
            }
            if (value.Exception != null)
            {
                text += $"<code>{value.Exception}</p>";
            }
            text += "</body></html>";
            SendEmail($"[{value.Machine}] Alert: {value.Application} ({value.Version}) - {value.Action}", text).GetAwaiter().GetResult();
        }
Esempio n. 2
0
        private void LocalLog(LogValue value)
        {
            using var connection = new SqlConnection(ConnectionStr);
            using var command    = new SqlCommand
                  {
                      CommandText = CommandStr,
                      Connection  = connection,
                      CommandType = System.Data.CommandType.Text
                  };
            var par = command.Parameters;

            par.AddWithValue("@1", LocalSqlTimeGuid(value.Time));
            par.AddWithValue("@2", (object)value.Application ?? DBNull.Value);
            par.AddWithValue("@3", (object)value.Action ?? DBNull.Value);
            par.AddWithValue("@4", (object)value.Machine ?? DBNull.Value);
            par.AddWithValue("@5", (object)value.Class ?? DBNull.Value);
            par.AddWithValue("@6", (object)value.Method ?? DBNull.Value);
            par.AddWithValue("@7", (object)value.Time ?? DBNull.Value);
            par.AddWithValue("@8", (object)value.Key ?? DBNull.Value);
            par.AddWithValue("@9", (object)value.Value ?? DBNull.Value);
            par.AddWithValue("@10", (object)value.Note ?? DBNull.Value);
            par.AddWithValue("@11", (object)value.TypeObj ?? DBNull.Value);
            par.AddWithValue("@12", (object)value.JsonObj ?? DBNull.Value);
            par.AddWithValue("@13", (object)value.Message ?? DBNull.Value);
            par.AddWithValue("@14", (object)value.Exception ?? DBNull.Value);
            par.AddWithValue("@15", (object)value.Version ?? DBNull.Value);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 3
0
        public void Log(LogValue value)
        {
            var path = Path.Combine(Folder, value.Application ?? "Default", $"{value.Time:yyyy-MM}", $"{value.Action}-{value.Time:yy-MM-dd}.log");
            var text = value.GetText();

            try
            {
                File.AppendAllText(path, text);
            }
            catch
            {
                var fileInfo = new FileInfo(path);
                Directory.CreateDirectory(fileInfo.DirectoryName);
                File.AppendAllText(path, text);
            }
        }
Esempio n. 4
0
 public void Log(LogValue value)
 {
     try
     {
         LocalLog(value);
     }
     catch (Exception ex)
     {
         LocalLog(value.Continue(c =>
         {
             c.Exception = "Sql Error\n" + ex.GetDescription();
             c.JsonObj   = null;
             c.Message   = null;
             c.Note      = null;
             c.TypeObj   = null;
             c.Value     = null;
         }));
     }
 }
Esempio n. 5
0
 public void Write(LogValue val)
 => Task.Run(() => GetAction(val.Action)?.Invoke(val));
Esempio n. 6
0
 public void Log(LogValue value) => Action?.Invoke(value);
Esempio n. 7
0
 public void Log(LogValue value)
 {
     using var client = new HttpClient();
     client.PostAsync(Uri, value, new JsonMediaTypeFormatter()).ConfigureAwait(false).GetAwaiter().GetResult();
 }
Esempio n. 8
0
 public void Log(LogValue value) => Debug.Write(value.GetText());
Esempio n. 9
0
 public void Log(LogValue value) => Console.WriteLine(value.GetText());