本文整理汇总了C#中NLog.ErrorException方法的典型用法代码示例。如果您正苦于以下问题:C# NLog.ErrorException方法的具体用法?C# NLog.ErrorException怎么用?C# NLog.ErrorException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLog
的用法示例。
在下文中一共展示了NLog.ErrorException方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadConfig
public static bool DownloadConfig(string downloadedZipPath, string AzureAccountName, string AzureAccountKey, string orgID, string studyID, string homeID, string configFilename, NLog.Logger logger=null)
{
Microsoft.WindowsAzure.CloudStorageAccount storageAccount = null;
Microsoft.WindowsAzure.StorageClient.CloudBlobClient blobClient = null;
Microsoft.WindowsAzure.StorageClient.CloudBlobContainer container = null;
Microsoft.WindowsAzure.StorageClient.CloudBlockBlob blockBlob = null;
string leaseId = null;
try
{
storageAccount = new Microsoft.WindowsAzure.CloudStorageAccount(new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey(AzureAccountName, AzureAccountKey), true);
blobClient = storageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference(AzureConfigContainerName);
if (configFilename == PackagerHelper.ConfigPackagerHelper.actualConfigFileName)
{
blockBlob = container.GetBlockBlobReference(ActualConfigBlobName(orgID, studyID, homeID, configFilename));
}
else if (configFilename == PackagerHelper.ConfigPackagerHelper.desiredConfigFileName)
{
blockBlob = container.GetBlockBlobReference(DesiredConfigBlobName(orgID, studyID, homeID, configFilename));
}
bool blobExists = BlockBlobExists(blockBlob);
if (blobExists)
leaseId = AcquireLease(blockBlob, logger); // Acquire Lease on Blob
else
return false;
if (blobExists && leaseId == null)
{
if (null != logger)
{
logger.Error("AcquireLease on Blob: " + ActualConfigBlobName(orgID, studyID, homeID, configFilename) + " Failed");
}
return false;
}
string url = blockBlob.Uri.ToString();
if (blockBlob.ServiceClient.Credentials.NeedsTransformUri)
{
url = blockBlob.ServiceClient.Credentials.TransformUri(url);
}
var req = BlobRequest.Get(new Uri(url), AzureBlobLeaseTimeout, null, leaseId);
blockBlob.ServiceClient.Credentials.SignRequest(req);
using (var reader = new BinaryReader(req.GetResponse().GetResponseStream()))
{
FileStream zipFile = new FileStream(downloadedZipPath, FileMode.OpenOrCreate);
reader.BaseStream.CopyTo(zipFile);
zipFile.Close();
}
req.GetResponse().GetResponseStream().Close();
ReleaseLease(blockBlob, leaseId); // Release Lease on Blob
return true;
}
catch (Exception e)
{
if (null != logger)
{
logger.ErrorException("DownloadConfig_Azure, downloadZipPath: " + downloadedZipPath, e);
}
ReleaseLease(blockBlob, leaseId);
return false;
}
}
示例2: DoLeaseOperation
private static void DoLeaseOperation(CloudBlob blob, string leaseId, Microsoft.WindowsAzure.StorageClient.Protocol.LeaseAction action, NLog.Logger logger)
{
try
{
if (blob == null || leaseId == null)
return;
var creds = blob.ServiceClient.Credentials;
var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString()));
var req = BlobRequest.Lease(transformedUri, AzureBlobLeaseTimeout, action, leaseId);
creds.SignRequest(req);
req.GetResponse().Close();
}
catch (WebException e)
{
if (null != logger)
{
logger.ErrorException("DoLeaseOperation, blob: " + blob.Name + ", leaseId: " + leaseId + ", action " + action, e);
}
}
}
示例3: AcquireLease
private static string AcquireLease(Microsoft.WindowsAzure.StorageClient.CloudBlockBlob blob, NLog.Logger logger)
{
try
{
var creds = blob.ServiceClient.Credentials;
var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString()));
var req = BlobRequest.Lease(transformedUri, AzureBlobLeaseTimeout, // timeout (in seconds)
Microsoft.WindowsAzure.StorageClient.Protocol.LeaseAction.Acquire, // as opposed to "break" "release" or "renew"
null); // name of the existing lease, if any
blob.ServiceClient.Credentials.SignRequest(req);
using (var response = req.GetResponse())
{
return response.Headers["x-ms-lease-id"];
}
}
catch (WebException e)
{
if (null != logger)
{
logger.ErrorException("AcquireLease, blob: " + blob, e);
}
return null;
}
}
示例4: UploadConfig
public static bool UploadConfig(string configZipPath, string AzureAccountName, string AzureAccountKey, string orgID, string studyID, string homeID, string desiredConfigFilename, NLog.Logger logger = null)
{
Microsoft.WindowsAzure.CloudStorageAccount storageAccount = null;
Microsoft.WindowsAzure.StorageClient.CloudBlobClient blobClient = null;
Microsoft.WindowsAzure.StorageClient.CloudBlobContainer container = null;
Microsoft.WindowsAzure.StorageClient.CloudBlockBlob blockBlob = null;
string leaseId = null;
try
{
storageAccount = new Microsoft.WindowsAzure.CloudStorageAccount(new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey(AzureAccountName, AzureAccountKey), true);
blobClient = storageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference(AzureConfigContainerName);
container.CreateIfNotExist();
blockBlob = container.GetBlockBlobReference(DesiredConfigBlobName(orgID, studyID, homeID, desiredConfigFilename));
bool blobExists = BlockBlobExists(blockBlob);
if (blobExists)
leaseId = AcquireLease(blockBlob, logger); // Acquire Lease on Blob
else
blockBlob.Container.CreateIfNotExist();
if (blobExists && leaseId == null)
{
if (null != logger)
{
logger.Error("AcquireLease on Blob: " + DesiredConfigBlobName(orgID, studyID, homeID, desiredConfigFilename) + " Failed");
}
return false;
}
string url = blockBlob.Uri.ToString();
if (blockBlob.ServiceClient.Credentials.NeedsTransformUri)
{
url = blockBlob.ServiceClient.Credentials.TransformUri(url);
}
var req = BlobRequest.Put(new Uri(url), AzureBlobLeaseTimeout, new Microsoft.WindowsAzure.StorageClient.BlobProperties(), Microsoft.WindowsAzure.StorageClient.BlobType.BlockBlob, leaseId, 0);
using (var writer = new BinaryWriter(req.GetRequestStream()))
{
writer.Write(File.ReadAllBytes(configZipPath));
writer.Close();
}
blockBlob.ServiceClient.Credentials.SignRequest(req);
req.GetResponse().Close();
ReleaseLease(blockBlob, leaseId); // Release Lease on Blob
return true;
}
catch (Exception e)
{
if (null != logger)
{
logger.ErrorException("UploadConfig_Azure, configZipPath: " + configZipPath, e);
}
ReleaseLease(blockBlob, leaseId);
return false;
}
}
示例5: IsFtpBinaryVersionPresent
internal static bool IsFtpBinaryVersionPresent(Uri uriRemoteDirPath, string version, string ftpUser, string ftpPassword, NLog.Logger logger)
{
bool present = false;
Version versionCheck = new Version(version);
try
{
string[] dirContents = SecureFtpRepoUpdate.ListDirectory(uriRemoteDirPath, ftpUser, ftpPassword, false /*details*/, true /*enableSSL*/);
for (int i = 0; i < dirContents.Length; ++i)
{
if (dirContents[i] == version)
continue;
Version ver = new Version(dirContents[i]);
if (ver == versionCheck)
{
present = true;
break;
}
}
}
catch (Exception e)
{
logger.ErrorException("Failed to retrieve the latest version from remote ftp server", e);
}
return present;
}
示例6: GetFtpHighestVersionFromDir
internal static Version GetFtpHighestVersionFromDir(Uri uriRemoteDirPath, string ftpUser, string ftpPassword, NLog.Logger logger)
{
string version = "0.0.0.0";
Version highest = new Version(version);
try
{
string[] dirContents = SecureFtpRepoUpdate.ListDirectory(uriRemoteDirPath, ftpUser, ftpPassword, false /*details*/, true /*enableSSL*/);
for (int i = 0; i < dirContents.Length; ++i)
{
if (dirContents[i] == "Latest")
continue;
Version ver = new Version(dirContents[i]);
if (ver > highest)
highest = ver;
}
}
catch (Exception e)
{
logger.ErrorException("Failed to retrieve the latest version from remote ftp server", e);
}
return highest;
}