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); }
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); }
public void Error(object message, Exception exception) { if (IsErrorEnabled) { log.ErrorException(message.ToString(), exception); } }
public void ErrorException(string message, Exception exception) { if (_logger != null) { _logger.ErrorException(message, exception); } }
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); } }
/// <summary> /// hàm thực hiện việc lấy thông tin khởi tạo đơn thuốc tổng hợp /// </summary> /// <param name="DepartmentID"></param> /// <param name="Status"></param> private void LaythongtinTongHopDonthuoc(int DepartmentID, int Status) { try { int id_kho = Utility.Int32Dbnull(cboKhoxuat.SelectedValue, -1); int id_khoa = Utility.Int32Dbnull(cboDepartment.SelectedValue, -1); Int16 loaiphieu = (Int16)(optLinhThuong.Checked ? 0 : 1);//0=Phieu thuong;1=Phieubosung if (m_Action == action.Insert) { Status = 0; //Nếu thêm mới ko cho phép load các đơn đã cấp phát cho dù chọn tất cả } else { Status = 1; //nếu là Update hiển thị tất cả các đơn thuốc chưa đề nghị cấp phát+các đơn thuốc được cấp phát cho phiếu đang làm } dsData = SPs.ThuocNoitruLaydanhsachdonthuocTonghoplinhthuocnoitru(id_khoa, id_kho, loaiphieu, KIEUTHUOC_VT, (Int16)Status, _IDCAPPHAT, chkCheck.Checked ? dtTuNgay.Value.ToString("dd/MM/yyyy") : "01/01/1900", chkCheck.Checked ? dtDenNgay.Value.ToString("dd/MM/yyyy") : "01/01/1900").GetDataSet(); dtDmucthuoc = dsData.Tables[2]; //Đơn thuốc và chi tiết cấp phát dtPhieucapphatchitiet = dsData.Tables[3]; //Chi tiết đơn thuốc dtPresDetail = dsData.Tables[1]; grdPresDetail.DataSource = dtPresDetail.DefaultView; //Danh sách các đơn thuốc đã hoặc chưa cấp phát dtPres = dsData.Tables[0]; Utility.SetDataSourceForDataGridEx(grdPres, dtPres, true, false, "1=1", ""); grdPres.MoveFirst(); //Tự động check chọn các đơn thuốc trong phiếu cấp phát Tudongchondonthuocdatonghop(); //Tổng hợp lại thông tin thuốc từ các đơn đã chọn-->lẽ ra mục này phải tự động load từ bảng Detail chứ ko cần tổng hợp lại-->SỬA SAU TongHopThuoc(); grdPres_SelectionChanged(grdPres, new EventArgs()); } catch (Exception ex) { log.ErrorException("Loi trong qua trinh khoi tao thong tin ", ex); } }
public void Error(string message, Exception exc = null) { if (exc == null) { InternalLogger.Error(message); } else { InternalLogger.ErrorException(message, exc); } }
public static void SetProcessName(string name) { try { if (prctl(15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes(name + "\0"), 0, 0, 0) != 0) { throw new ApplicationException(_("Error setting process name: " + Mono.Unix.Native.Stdlib.GetLastError())); } } catch (Exception ex) { logger.ErrorException("Couldn't set process name, ignoring.", ex); } }
private bool IsValidRepositoryAccountPresent() { bool valid = true; try { string[] directories = SecureFtpRepoUpdate.ListDirectory(new Uri(this.formRepoAccountInfo.RepoAccountHost + ":" + this.formRepoAccountInfo.RepoAccountPort), this.formRepoAccountInfo.RepoAccountLogin, this.formRepoAccountInfo.RepoAccountPassword, false, true ); } catch (Exception ex) { logger.ErrorException("Failed to list directories on the ftp server", ex); valid = false; } return(valid); }
/// <summary> /// writes error, generally used for critical errors /// </summary> /// <param name="msg">additional info, optional parameter</param> /// <param name="e">exception, optional parameter</param> public void WriteToLog(string msg, Exception e) { if (!String.IsNullOrEmpty(msg) && e != null) { m_Logger.ErrorException(msg, e); } else if (!String.IsNullOrEmpty(msg)) { m_Logger.Error(msg); } else if (e != null) { m_Logger.Error(e); } }
private void HandleException(Exception ex) { if (logger == null) { LoggingConfiguration config = new LoggingConfiguration(); ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget(); consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"; config.AddTarget("console", consoleTarget); LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget); config.LoggingRules.Add(rule1); LogManager.Configuration = config; logger = LogManager.GetCurrentClassLogger(); //new NLog.LogFactory().GetCurrentClassLogger(); } logger.ErrorException("error", ex); }
protected void btnLoggerFileInDisk_Click(object sender, EventArgs e) { int zero = 0; string errorMessage = string.Empty; int result = 0; try { errorMessage = txtLoggerFileInDisk.Text; result = 5 / zero; } catch (DivideByZeroException ex) { //Using Logger to write a file in disk: NL.Logger logger = NL.LogManager.GetCurrentClassLogger(); logger.ErrorException(errorMessage, ex); txtLoggerFileInDisk.Text = "¡Log escrito OK en archivo de disco!"; } }
protected void btnLoggerDB_Click(object sender, EventArgs e) { int zero = 0; string errorMessage = string.Empty; int result = 0; try { errorMessage = txtLoggerDBMessage.Text; result = 5 / zero; } catch (DivideByZeroException ex) { //Using Logger to write add a row into a database table: NL.Logger logger = NL.LogManager.GetLogger("databaseLogger"); logger.ErrorException(errorMessage, ex); txtLoggerDBMessage.Text = "¡Log escrito OK en Base de Datos!"; } }
public string Command(string cmdAlias, string[] args) { cmdAlias = cmdAlias.ToLower(); var cmd = _commands.FirstOrDefault(c => c.CommandAliases != null && c.CommandAliases.Any(a => a.ToLower() == cmdAlias)); if (cmd == null) { return("%!The command %@" + cmdAlias + "%@ is not valid for server extension \"" + ID + "\".%!"); } try { return(cmd.Execute(this, args)); } catch (Exception ex) { _logger.ErrorException("COMMAND EXCEPTION" + args.Concat(" "), ex); throw; } }
private void OpenSequenceFromFile(string filename) { try { IEditorUserInterface editor = EditorService.Instance.CreateEditor(filename); if (editor == null) { Logging.Error("Can't find an appropriate editor to open file " + filename); MessageBox.Show("Can't find an editor to open this file type. (\"" + Path.GetFileName(filename) + "\")", "Error opening file", MessageBoxButtons.OK); } else { _OpenEditor(editor); } } catch (Exception ex) { Logging.ErrorException("Error trying to open file '" + filename + "': ", ex); MessageBox.Show("Error trying to open file '" + filename + "'.", "Error opening file", MessageBoxButtons.OK); } }
internal static async Task <string> Get1ponCover(string id) { var url = string.Format("https://www.1pondo.tv/dyn/phpauto/movie_details/movie_id/{0}.json", id.Replace("-1pon", string.Empty)); using (var handler = new HttpClientHandler()) using (var client = new HttpClient(handler)) { try { var response = await client.GetStringAsync(url); dynamic js = JsonConvert.DeserializeObject(response); return(Convert.ToString(js.ThumbHigh)); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); return(string.Empty); } } }
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); } } }
public void ErrorException(string message, Exception exception, params object[] args) { _logger.ErrorException(Format(message, args), exception); }
public void Exception(String message, Exception ex) { nlog.ErrorException(message, ex); }
public void Error(string message, Exception ex) { logger.ErrorException(AppendInfomation(message), ex); }
/// <summary> /// Logs the exception. /// </summary> /// <param name="exception">The exception.</param> public void Error(Exception exception) { _innerLogger.ErrorException(exception.Message, exception); }
public MainClass(string [] args) { Ticker.Tick(); // required for the MS .NET runtime that doesn't initialize glib automatically if (!GLib.Thread.Supported) { GLib.Thread.Init(); } // Connect to dbus DBusInstance DBusInstance = ServiceManager.Get <DBusInstance> (); DBusInstance.Initialise(); if (DBusInstance.AlreadyRunning) { Console.WriteLine("Already running"); DBusInstance.CommandParser.ParseCommands(args); return; } DBusInstance.CommandParser.RunCommand += HandleCommand; Ticker.Tick(); CheckDataFolders(); Ticker.Tock("Checking folders"); foreach (string arg in args) { HandleCommand(arg); } Ticker.Tick(); if (DebugEnabled) { BuildNlogConfig(); } logger = DebugEnabled ? NLog.LogManager.GetCurrentClassLogger() : new EmptyLogger(); Ticker.Tock("NLog"); logger.Info("Starting Monsoon"); Ticker.Tick(); SetProcessName("monsoon"); Ticker.Tock("Setting process name"); string localeDir = Path.Combine(Defines.ApplicationDirectory, "locale"); if (!Directory.Exists(localeDir)) { localeDir = Path.Combine(Defines.InstallPrefix, "share"); localeDir = Path.Combine(localeDir, "locale"); } Ticker.Tick(); Mono.Unix.Catalog.Init("monsoon", localeDir); logger.Debug("Using locale data from: {0}", localeDir); Application.Init("monsoon", ref args); Ticker.Tock("Locale"); try { SettingsManager.Restore <EngineSettings> (SettingsManager.EngineSettings); SettingsManager.Restore <PreferencesSettings> (SettingsManager.Preferences); SettingsManager.Restore <TorrentSettings> (SettingsManager.DefaultTorrentSettings); } catch (Exception ex) { logger.Error("Couldn't restore old settings: {0}", ex.Message); } try { Ticker.Tick(); mainWindow = new MainWindow(); Ticker.Tock("Instantiating window"); } catch (Exception e) { logger.ErrorException(e.Message, e); Environment.Exit(0); } LoadAddins(); GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnUnhandledException); Ticker.Tock("Total time:"); Application.Run(); try { SettingsManager.Store <EngineSettings> (SettingsManager.EngineSettings); SettingsManager.Store <PreferencesSettings> (SettingsManager.Preferences); SettingsManager.Store <TorrentSettings> (SettingsManager.DefaultTorrentSettings); } catch (Exception ex) { logger.Error("Could save engine settings: {0}", ex.Message); } ServiceManager.Get <ListenPortController> ().Stop(); mainWindow.Destroy(); }
public static void Error(string message, Exception exception) { LogHelper.ErrorException(message, exception); }
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); } }
public MainClass(string [] args) { Ticker.Tick(); // required for the MS .NET runtime that doesn't initialize glib automatically if (!GLib.Thread.Supported) GLib.Thread.Init(); // Connect to dbus DBusInstance DBusInstance = ServiceManager.Get <DBusInstance> (); DBusInstance.Initialise (); if (DBusInstance.AlreadyRunning) { Console.WriteLine("Already running"); DBusInstance.CommandParser.ParseCommands (args); return; } DBusInstance.CommandParser.RunCommand += HandleCommand; Ticker.Tick(); CheckDataFolders(); Ticker.Tock ("Checking folders"); foreach (string arg in args) HandleCommand (arg); Ticker.Tick (); if (DebugEnabled) { BuildNlogConfig(); } logger = DebugEnabled ? NLog.LogManager.GetCurrentClassLogger () : new EmptyLogger (); Ticker.Tock("NLog"); logger.Info("Starting Monsoon"); Ticker.Tick (); SetProcessName("monsoon"); Ticker.Tock("Setting process name"); string localeDir = Path.Combine(Defines.ApplicationDirectory, "locale"); if (!Directory.Exists(localeDir)) { localeDir = Path.Combine(Defines.InstallPrefix, "share"); localeDir = Path.Combine(localeDir, "locale"); } Ticker.Tick (); Mono.Unix.Catalog.Init("monsoon", localeDir); logger.Debug("Using locale data from: {0}", localeDir); Application.Init("monsoon", ref args); Ticker.Tock("Locale"); try { SettingsManager.Restore <EngineSettings> (SettingsManager.EngineSettings); SettingsManager.Restore <PreferencesSettings> (SettingsManager.Preferences); SettingsManager.Restore <TorrentSettings> (SettingsManager.DefaultTorrentSettings); } catch (Exception ex) { logger.Error("Couldn't restore old settings: {0}", ex.Message); } try { Ticker.Tick(); mainWindow = new MainWindow (); Ticker.Tock ("Instantiating window"); } catch(Exception e) { logger.ErrorException(e.Message, e); Environment.Exit (0); } LoadAddins (); GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnUnhandledException); Ticker.Tock ("Total time:"); Application.Run(); try { SettingsManager.Store <EngineSettings> (SettingsManager.EngineSettings); SettingsManager.Store <PreferencesSettings> (SettingsManager.Preferences); SettingsManager.Store <TorrentSettings> (SettingsManager.DefaultTorrentSettings); } catch (Exception ex) { logger.Error("Could save engine settings: {0}", ex.Message); } ServiceManager.Get <ListenPortController> ().Stop (); mainWindow.Destroy (); }
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); } }
/// <summary> /// 输出错误日志 Error 级别。 /// </summary>> /// <param name="msg">错误消息体</param> /// <param name="ex">错误类</param> public void Log(object message, Exception e) { log4.ErrorException(EncryptPassword(message), e); }
public void Error(string message, Exception exception) { logger.ErrorException(message, exception); }