/// <summary>
 /// Enables to set the StatusCode
 /// </summary>
 /// <param name="severity"></param>
 public DsoHttpResult(SeverityEnum severity)
 {
     StatusCode    = EnumSeverity.GetCode(severity);
     Notifications = new List <DsoHttpResultNotification>();
     MutationCode  = EnumMutation
                     .GetCode(MutationEnum.None);
 }
 /// <summary>
 /// Successful constructor
 /// </summary>
 public DsoHttpResult()
 {
     StatusCode    = EnumSeverity.GetCode(SeverityEnum.Ok);
     Notifications = new List <DsoHttpResultNotification>();
     MutationCode  = EnumDsoHttpResultMutation
                     .GetCode(DsoHttpResultMutationEnum.None);
 }
 public DsoHttpResultNotification(
     SeverityEnum severity,
     string message)
 {
     SeverityCode = EnumSeverity.GetCode(severity);
     Message      = message;
 }
 protected DsoHttpResult(
     SeverityEnum severity,
     bool hasMoreResults,
     MutationEnum mutation = MutationEnum.None) :
     this()
 {
     StatusCode     = EnumSeverity.GetCode(severity);
     MutationCode   = EnumMutation.GetCode(mutation);
     HasMoreResults = hasMoreResults;
 }
Beispiel #5
0
 private async Task WriteLogAsync(
     string message,
     string topic,
     SeverityEnum severity = SeverityEnum.Debug,
     string memberName     = "",
     string filePath       = "",
     int lineNumber        = -1)
 {
     await _logWriter.WriteLogAsync(
         _userId, _companyId, topic,
         EnumSeverity.GetCode(severity),
         Environment.MachineName,
         memberName, filePath, lineNumber,
         message, DateTime.UtcNow);
 }
        private void WriteLog(
            SeverityEnum severity, string topic, string context, string message)
        {
            using (var cn = new SqlConnection(_msSqlConnectionString))
            {
                cn.Open();

                context = context?.Replace("'", "''") ?? "na";
                if (context.Length > _contextLength)
                {
                    context = context.Substring(0, _contextLength);
                }

                // topic
                string pTopic;
                if (string.IsNullOrEmpty(topic))
                {
                    pTopic = "NULL";
                }
                else
                {
                    if (topic.Length > _topicLength)
                    {
                        topic = topic.Substring(0, _topicLength);
                    }
                    topic  = topic.Replace("'", "''");
                    pTopic = $"'{topic}'";
                }

                message = message?.Replace("'", "''") ?? "na";

                // userId
                string pUserId;
                if (string.IsNullOrEmpty(_userId))
                {
                    pUserId = "NULL";
                }
                else
                {
                    if (_userId.Length > _userIdLength)
                    {
                        _userId = _userId.Substring(0, _userIdLength);
                    }
                    _userId = _userId.Replace("'", "''");
                    pUserId = $"'{_userId}'";
                }

                // companyId
                string pCompanyId;
                if (string.IsNullOrEmpty(_companyId))
                {
                    pCompanyId = "NULL";
                }
                else
                {
                    if (_companyId.Length > _companyIdLength)
                    {
                        _companyId = _companyId.Substring(0, _companyIdLength);
                    }
                    _companyId = _companyId.Replace("'", "''");
                    pCompanyId = $"'{_companyId}'";
                }

                var machineName = Environment.MachineName;
                if (machineName.Length > _machineNameLength)
                {
                    machineName = machineName.Substring(0, _machineNameLength);
                }
                machineName = machineName.Replace("'", "''");

                var cmdText = $"INSERT INTO [{_tableSchema}].[{_tableName}] "
                              + "( "
                              + $" [{_userIdColumnName}], "
                              + $" [{_companyIdColumnName}], "
                              + $" [{_severityCodeColumnName}], "
                              + $" [{_machineNameColumnName}], "
                              + $" [{_topicColumnName}], "
                              + $" [{_contextColumnName}], "
                              + $" [{_messageColumnName}], "
                              + $" [{_createDateColumnName}] "
                              + ")"
                              + "VALUES "
                              + "( "
                              + $"{pUserId}, "
                              + $"{pCompanyId}, "
                              + $"'{EnumSeverity.GetCode(severity)}', "
                              + $"'{machineName}', "
                              + $"{pTopic}, "
                              + $"'{context}', "
                              + $"'{message}', "
                              + $"'{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss.sss}' "
                              + ")";

                var cmd = new SqlCommand(cmdText, cn)
                {
                    CommandType = CommandType.Text
                };

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error : " + e.GetDeepMessage());
                }
                finally
                {
                    cn.Close();
                }
            }
        }
        private void WriteLog(
            SeverityEnum severity, string context, string message)
        {
            using (var cn = new SqlConnection(_msSqlConnectionString))
            {
                cn.Open();

                context = context?.Replace("'", "''") ?? "na";
                if (context.Length > 256)
                {
                    context = context.Substring(0, 256);
                }

                message = message.Replace("'", "''");

                var uId = UserId.HasValue ? $"'{UserId.Value}'" : "NULL";

                var cId = CompanyId.HasValue ? $"'{CompanyId.Value}'" : "NULL";

                var machineName = Environment.MachineName.Replace("'", "''");
                if (machineName.Length > 50)
                {
                    machineName = machineName.Substring(0, 50);
                }

                var cmdText = "INSERT INTO ApplicationLog "
                              + "( "
                              + " [AspNetUserId], "
                              + " [CompanyId], "
                              + " [SeverityCode], "
                              + " [Machine], "
                              + " [Context], "
                              + " [Message], "
                              + " [CreateDateUtc] "
                              + ")"
                              + "VALUES "
                              + "( "
                              + $"{uId}, "
                              + $"{cId}, "
                              + $"'{EnumSeverity.GetCode(severity)}', "
                              + $"'{machineName}', "
                              + $"'{context}', "
                              + $"'{message}', "
                              + $"'{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss.sss}' "
                              + ")";

                var cmd = new SqlCommand(cmdText, cn)
                {
                    CommandType = CommandType.Text
                };

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error : " + e.GetDeepMessage());
                }
                finally
                {
                    cn.Close();
                }
            }
        }