public static int Rethrow() {
   int i = 0;
   int j = 0;
   System.ApplicationException appExp = new System.ApplicationException();
   try {
     i = i + 1;
     try {
       i = i + 1;
       throw appExp;
     } catch (System.ApplicationException e) {
       if (i != 2) {
         j = 1;
       }
       i = i + 5;
       throw;
     } catch (System.Exception) {
       j = 1;
     } finally {
       if (i != 7) {
         j = 1;
       }
       i = i + 3;
     }
     i = i + 100;
   } catch (System.ApplicationException) {
     if (i != 10) {
       j = 1;
     }
     i = i + 8;
   } catch (System.Exception) {
     j = 1;
   } finally {
     if (i != 18) {
       j = 1;
     }
     i = i + 10;
   }
   if (j == 1) {
     return 1;
   }
   return i == 28 ? 0 : i;
 }
 public static int ThrowAcrossMethods3() {
   int i = 0;
   int j = 0;
   System.Exception exp = new System.Exception();
   System.ApplicationException appExp = new System.ApplicationException();
   try {
     i = i + 1;
     throw exp;
     j = 1;
   } catch (System.ApplicationException) {
     j = 1;
   } finally {
     if (i != 1) {
       j = 1;
     }
     i = i + 2;
   }
   if (j == 1) {
     return 1;
   }
   return i == 1 ? 0 : 1;
 }
 public static int ThrowCatchSimple3() {
   int i = 0;
   int j = 0;
   System.Exception exp = new System.Exception();
   System.ApplicationException appExp = new System.ApplicationException();
   try {
     i = i + 1;
     try {
       i = i + 1;
       throw appExp;
     } finally {
       if (i != 1) {
         j = 1;
       }
       i = i + 2;
     }
   } finally {
     if (i != 3) {
       j = 1;
     }
     i = i + 5;
   }
   if (j == 1) {
     return 1;
   }
   return i == 8 ? 0 : 1;
 }
 public static int ThrowCatchSimple6() {
   int i = 0;
   int j = 0;
   System.Exception exp = new System.Exception();
   System.ApplicationException appExp = new System.ApplicationException();
   try {
     i = i + 1;
     try {
       i = i + 1;
       throw exp;
     } catch (System.ApplicationException) {
       j = 1;
     } finally {
       if (i != 2) {
         j = 1;
       }
       i = i + 3;
     }
     i = i + 100;
   } catch (System.ApplicationException) {
     j = 1;
   } catch (System.Exception) {
     if (i != 5) {
       j = 1;
     }
     i = i + 5;
   } finally {
     if (i != 10) {
       j = 1;
     }
     i = i + 8;
   }
   if (j == 1) {
     return 1;
   }
   return i == 18 ? 0 : i;
 }
 public static int ThrowCatchSimple() {
   int i = 0;
   int j = 0;
   System.Exception exp = new System.Exception();
   System.ApplicationException appExp = new System.ApplicationException();
   try {
     i = i + 1;
     throw exp;
   } catch (System.Exception) {
     if (i != 1) {
       j = 1;
     }
     i = i + 2;
   }
   if (j == 1) {
     return 1;
   }
   return i == 3 ? 0 : 1;
 }
Esempio n. 6
0
 public void LogWarning(string message)
 {
     var e = new System.ApplicationException(message);
     this.LogError(e);
 }
Esempio n. 7
0
 public string LogFatal(string message)
 {
     var e = new System.ApplicationException(message);
     return this.LogError(e);
 }
Esempio n. 8
0
 /// <summary> Clears the current target error conditions, if any. Note that a thread
 /// in the pool might have set the error conditions since the last check
 /// and that those error conditions will be lost. Likewise, before
 /// returning from this method another thread might set the error
 /// conditions. There is no guarantee that no error conditions exist when
 /// returning from this method.
 ///
 /// <P>In order to ensure that no error conditions exist when returning
 /// from this method cooperation from the targets and the thread using this
 /// pool is necessary (i.e. currently no targets running or waiting to
 /// run).
 ///
 /// </summary>
 public virtual void clearTargetErrors()
 {
     // Clear the error and runtime exception conditions
     targetE  = null;
     targetRE = null;
 }
        private async System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> PostData(System.DateTimeOffset timestamp, System.String logType, System.String message, System.String customerId, System.String sharedKey)

        {
            var url = $"https://{customerId}.ods.opinsights.azure.com/api/logs?api-version=2016-04-01";

#if DEBUG
            System.Console.WriteLine($"{{ \"{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName}.{System.Reflection.MethodBase.GetCurrentMethod().Name}\" :  {{");
            System.Console.WriteLine($"\"customerId\" : \"{customerId}\",");
            System.Console.WriteLine($"\"logType\" : \"{logType}\",");
            System.Console.WriteLine($"\"sharedKeySecret\" : \"{sharedKey}\",");
            System.Console.WriteLine($"\"timestamp\" : \"{timestamp}\",");
            System.Console.WriteLine($"\"message\" : {{ {message}  }}, ");
            System.Console.WriteLine(url);
#endif

            var response =
                new System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage>(() => null);
            var datestring    = System.DateTime.UtcNow.ToString("r");
            var authorization = this.GetAuthorizationHash(message, datestring, customerId, sharedKey);
            var client        = new System.Net.Http.HttpClient
            {
                Timeout = this.WebTimeOut
            };
            if (!Connectivity.NetworkStatus.IsAvailable)
            {
                var err = new System.ApplicationException("The Internet is not available");
                throw err;
            }
            else
            {
                try
                {
                    // Note the formatting of the datestring vs timestamp

                    client.DefaultRequestHeaders.Add("Accept", "application/json");
                    client.DefaultRequestHeaders.Add("Log-Type", logType);
                    client.DefaultRequestHeaders.Add("Authorization", authorization);
                    client.DefaultRequestHeaders.Add("x-ms-date", datestring);

                    // let the Log Analytics HTTP DataCollector API assign the Timestamp
                    client.DefaultRequestHeaders.Add("time-generated-field", timestamp.ToIso8601());

                    System.Net.Http.HttpContent httpContent = new System.Net.Http.StringContent(message, System.Text.Encoding.UTF8);
                    httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    response = client.PostAsync(new System.Uri(url), httpContent);
#if DEBUG
                    System.Console.WriteLine($"\"PostDate response\": {{ {response.ToJson()} }}");
#endif
                }
#pragma warning disable 168
                catch (System.Exception excep)
#pragma warning restore 168
                {
                    var stateMsg =
                        $"Error E00650 in \"{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName}.{System.Reflection.MethodBase.GetCurrentMethod().Name}\" sending \"{message.ToJson()}\" to \"{url}\"";
                    // ReSharper disable once UnusedVariable
                    var ex         = new System.Exception(stateMsg, excep);
                    var logMessage = new Generic.LogMessage <System.String>(Microsoft.Extensions.Logging.LogLevel.Error, Events.E00650, stateMsg, excep, this.AzureDataCollectorFormatter);
                    this.AddMessage(logMessage);
#if DEBUG
                    System.Console.WriteLine($"\"PostDate Exception\": {{ {excep.ToJson()} }}");
#endif
                }
#if DEBUG
                finally
                {
                    System.Console.WriteLine($"}}");
                }
#endif
                return(await response);
            }
        }