本文整理汇总了C#中Error类的典型用法代码示例。如果您正苦于以下问题:C# Error类的具体用法?C# Error怎么用?C# Error使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Error类属于命名空间,在下文中一共展示了Error类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
public override string Log(Error error)
{
if (error == null)
{
throw new ArgumentNullException(nameof(error));
}
var errorXml = ErrorXml.EncodeString(error);
using (var scope = DataAccessScope.CreateReadCommitted())
{
var dbElmahError = dataModel.ElmahErrors.Create();
dbElmahError.Application = ApplicationName;
dbElmahError.Host = error.HostName;
dbElmahError.Type = error.Type;
dbElmahError.Source = error.Source;
dbElmahError.Message = error.Message;
dbElmahError.User = error.User;
dbElmahError.StatusCode = error.StatusCode;
dbElmahError.TimeUtc = error.Time;
dbElmahError.AllXml = errorXml;
scope.Complete();
return dbElmahError.Id.ToString();
}
}
示例2: Append
protected override void Append(log4net.Core.LoggingEvent loggingEvent)
{
if (this._ErrorLog != null)
{
Error error;
if (loggingEvent.ExceptionObject != null)
{
error = new Error(loggingEvent.ExceptionObject);
}
else
{
error = new Error();
}
error.Time = DateTime.Now;
if (loggingEvent.MessageObject != null)
{
error.Message = loggingEvent.MessageObject.ToString();
}
error.Detail = base.RenderLoggingEvent(loggingEvent);
error.HostName = this._HostName;
error.User = loggingEvent.Identity;
error.Type = "log4net - " + loggingEvent.Level; // maybe allow the type to be customized?
this._ErrorLog.Log(error);
}
}
示例3: ErrorLoggingEventArgs
public ErrorLoggingEventArgs(Error error)
{
if (error == null)
throw new ArgumentNullException("error");
_error = error;
}
示例4: Log
/// <summary>
/// Logs an error in log for the application.
/// </summary>
public override string Log(Error error)
{
if (error == null)
throw new ArgumentNullException("error");
string errorXml = ErrorXml.EncodeString(error);
Guid id = Guid.NewGuid();
using (MySqlConnection cn = new MySqlConnection(ConnectionString))
{
using (MySqlCommand cmd = new MySqlCommand("Elmah_LogError", cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pErrorId", id.ToString());
cmd.Parameters.AddWithValue("@pApplication", ApplicationName);
cmd.Parameters.AddWithValue("@pHost", error.HostName);
cmd.Parameters.AddWithValue("@pType", error.Type);
cmd.Parameters.AddWithValue("@pSource", error.Source);
cmd.Parameters.AddWithValue("@pMessage", error.Message);
cmd.Parameters.AddWithValue("@pUser", error.User);
cmd.Parameters.AddWithValue("@pStatusCode", error.StatusCode);
cmd.Parameters.AddWithValue("@pTimeUtc", error.Time.ToUniversalTime());
cmd.Parameters.AddWithValue("@pAllXml", errorXml);
cn.Open();
cmd.ExecuteNonQuery();
return id.ToString();
}
}
}
示例5: Decode
/// <summary>
/// Decodes an <see cref="Error"/> object from its XML representation.
/// </summary>
public static Error Decode(XmlReader reader)
{
if (reader == null) throw new ArgumentNullException("reader");
if (!reader.IsStartElement()) throw new ArgumentException("Reader is not positioned at the start of an element.", "reader");
//
// Read out the attributes that contain the simple
// typed state.
//
var error = new Error();
ReadXmlAttributes(reader, error);
//
// Move past the element. If it's not empty, then
// read also the inner XML that contains complex
// types like collections.
//
var isEmpty = reader.IsEmptyElement;
reader.Read();
if (!isEmpty)
{
ReadInnerXml(reader, error);
reader.ReadEndElement();
}
return error;
}
示例6: typeof
void ITableEntity.ReadEntity(IDictionary<string, EntityProperty> properties, Microsoft.WindowsAzure.Storage.OperationContext operationContext)
{
// This can occasionally fail because someone didn't finish creating the entity yet.
EntityProperty value;
if (properties.TryGetValue("SerializedError", out value))
{
Error = ErrorXml.DecodeString(value.StringValue);
}
else
{
Error = new Error
{
ApplicationName = "TableErrorLog",
StatusCode = 999,
HostName = Environment.MachineName,
Time = DateTime.UtcNow,
Type = typeof(Exception).FullName,
Detail = "Error Log Entry is Corrupted/Missing in Table Store"
};
return;
}
if (properties.TryGetValue("Detail", out value))
{
Error.Detail = value.StringValue;
}
if (properties.TryGetValue("WebHostHtmlMessage", out value))
{
Error.WebHostHtmlMessage = value.StringValue;
}
}
示例7: Encode
/// <summary>
/// Encodes the default JSON representation of an <see cref="Error"/>
/// object to a <see cref="TextWriter" />.
/// </summary>
/// <remarks>
/// Only properties and collection entires with non-null
/// and non-empty strings are emitted.
/// </remarks>
public static void Encode(Error error, TextWriter writer)
{
if (error == null) throw new ArgumentNullException("error");
if (writer == null) throw new ArgumentNullException("writer");
EncodeEnclosed(error, new JsonTextWriter(writer));
}
示例8: InternalServerError
protected virtual IActionResult InternalServerError(Error error)
{
if (error == null) throw new ArgumentNullException("error", "error is null");
foreach (var message in error.Messages)
Logger.LogError(message);
return new ObjectResult(error) { StatusCode = 500 };
}
示例9: GenerateError
private static Error GenerateError(int maxErrorNestingLevel = 3, bool generateData = true, int currentNestingLevel = 0) {
var error = new Error();
error.Message = @"Generated exception message.";
error.Type = TestConstants.ExceptionTypes.Random();
if (RandomHelper.GetBool())
error.Code = RandomHelper.GetRange(-234523453, 98690899).ToString();
if (generateData) {
for (int i = 0; i < RandomHelper.GetRange(1, 5); i++) {
string key = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));
while (error.Data.ContainsKey(key) || key == Event.KnownDataKeys.Error)
key = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));
error.Data.Add(key, RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 25)));
}
}
var stack = new StackFrameCollection();
for (int i = 0; i < RandomHelper.GetRange(1, 10); i++)
stack.Add(GenerateStackFrame());
error.StackTrace = stack;
if (currentNestingLevel < maxErrorNestingLevel && RandomHelper.GetBool())
error.Inner = GenerateError(maxErrorNestingLevel, generateData, currentNestingLevel + 1);
return error;
}
示例10: KeyVaultClientException
/// <summary>
/// Constructor
/// </summary>
/// <param name="status">The HTTP response status code</param>
/// <param name="error">The Error object returned by the service</param>
public KeyVaultClientException( HttpStatusCode status, Uri requestUri, Error error = null )
: base( GetExceptionMessage( error ) )
{
Error = error;
RequestUri = requestUri;
Status = status;
}
示例11: WorkDB
/// <summary>
/// Конструктор
/// </summary>
/// <param name="aConnectionString">строка соединения</param>
public WorkDB(string aConnectionString)
{
mCn = new OleDbConnection(aConnectionString);
mErr = new Error();
mTxn = null;
mIsInternalTransaction = false;
}
示例12: GetExceptionMessage
private static string GetExceptionMessage( Error error )
{
if ( error != null && !string.IsNullOrWhiteSpace( error.Message ) )
return error.Message;
return "Service Error information was not available";
}
示例13: Error
/// <summary>
/// Constructor
/// </summary>
public Error( Exception ex )
{
Message = ex.Message;
if( ex.InnerException != null )
InnerError = new Error( ex.InnerException );
}
示例14: Enqueue
public void Enqueue(Error error) {
Manifest manifest = Manifest.FromError(error);
manifest.LastAttempt = DateTime.MinValue;
_data.Add(Tuple.Create(manifest, error));
while (_data.Count > MaxItems)
_data.RemoveAt(0);
}
示例15: RepublishError
public void RepublishError(Error error, QueueParameters parameters)
{
using (var connection = HosepipeConnection.FromParamters(parameters))
using (var model = connection.CreateModel())
{
try
{
if (error.Exchange != string.Empty)
{
model.ExchangeDeclarePassive(error.Exchange);
}
var properties = model.CreateBasicProperties();
error.BasicProperties.CopyTo(properties);
var body = Encoding.UTF8.GetBytes(error.Message);
model.BasicPublish(error.Exchange, error.RoutingKey, properties, body);
}
catch (OperationInterruptedException)
{
Console.WriteLine("The exchange, '{0}', described in the error message does not exist on '{1}', '{2}'",
error.Exchange, parameters.HostName, parameters.VHost);
}
}
}