private void ProcessData(byte[] bytes) { var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); try { var json = JObject.Parse(data); ApplyFilters(json); ProcessJson(json); _parsedMessages++; } catch (Exception ex) { var jex1 = LogErrors.LogException(string.Format("Invalid JSON: {0}", data), ex); if (jex1 != null) { ProcessJson(jex1); } var msg = string.Format("Bad JSON: {0}", data); LogManager.GetCurrentClassLogger().Warn(msg, ex); _parseErrors++; } }
public static void AddErrorInLog(string NameError, string DescrError) { try { using (AvtoritetEntities entities = new AvtoritetEntities()) { LogErrors entity = new LogErrors(); string hostName = Dns.GetHostName(); string str2 = ""; for (int i = 0; i < Dns.GetHostEntry(hostName).AddressList.Length; i++) { if (!Dns.GetHostEntry(hostName).AddressList[i].IsIPv6LinkLocal) { if (str2 != "") { str2 = str2 + ", "; } str2 = str2 + Dns.GetHostEntry(hostName).AddressList[i].ToString(); } } string userName = Environment.UserName; string machineName = Environment.MachineName; entity.Computer = hostName + ", " + str2 + ", " + userName + ", " + machineName; entity.DateError = new DateTime?(DateTime.Now); entity.ExeName = "Лаунчер"; entity.NameError = NameError; entity.DescrError = DescrError; entities.LogErrors.Add(entity); entities.SaveChanges(); } } catch { } }
/// <summary> /// Verifies the deployment model and waits till it reaches zero deployment errors. /// </summary> /// <param name="self"></param> /// <param name="configure">Builder infrastructure for the deployment model</param> /// <returns></returns> public static async Task VerifyDeploymentModelAsync(this Hub self, DeploymentModel model) { var awaitable = self.VerifyObservable(model) .Do(LogErrors(self)) .Where(x => x.Length == 0) .FirstAsync() .GetAwaiter(); var firstErors = model.Verify(self.Protocol); if (firstErors.Length > 0) { LogErrors(self)(firstErors); await awaitable; } }
protected virtual void Application_Error(Object sender, EventArgs e) { var context = HttpContext.Current; var ex = context.Server.GetLastError(); //Берём последнюю ошибку из контекста и логгируем LogErrors.LogedError(ex); }
/// <summary> /// Добавить сохранить /// </summary> /// <param name="LogErrors"></param> /// <returns></returns> public long SaveLogErrors(LogErrors LogErrors) { LogErrors dbEntry; try { if (LogErrors.ID == 0) { dbEntry = new LogErrors() { ID = 0, DateTime = LogErrors.DateTime, UserName = LogErrors.UserName, UserHostName = LogErrors.UserHostName, UserHostAddress = LogErrors.UserHostAddress, PhysicalPath = LogErrors.PhysicalPath, UserMessage = LogErrors.UserMessage, Service = LogErrors.Service, EventID = LogErrors.EventID, HResult = LogErrors.HResult, InnerException = LogErrors.InnerException, Message = LogErrors.Message, Source = LogErrors.Source, StackTrace = LogErrors.StackTrace }; context.LogErrors.Add(dbEntry); } else { dbEntry = context.LogErrors.Find(LogErrors.ID); if (dbEntry != null) { dbEntry.DateTime = LogErrors.DateTime; dbEntry.UserName = LogErrors.UserName; dbEntry.UserHostName = LogErrors.UserHostName; dbEntry.UserHostAddress = LogErrors.UserHostAddress; dbEntry.PhysicalPath = LogErrors.PhysicalPath; dbEntry.UserMessage = LogErrors.UserMessage; dbEntry.Service = LogErrors.Service; dbEntry.EventID = LogErrors.EventID; dbEntry.HResult = LogErrors.HResult; dbEntry.InnerException = LogErrors.InnerException; dbEntry.Message = LogErrors.Message; dbEntry.Source = LogErrors.Source; dbEntry.StackTrace = LogErrors.StackTrace; } } context.SaveChanges(); } catch (Exception e) { e.SaveErrorMethod(String.Format("SaveLogErrors(LogErrors={0})", LogErrors.GetFieldsAndValue()), blog); return(-1); } return(dbEntry.ID); }
protected virtual void Application_Error(Object sender, EventArgs e) { var context = HttpContext.Current; var ex = context.Server.GetLastError(); //if (ex.GetType() == typeof (HttpException)) var ip = HttpContext.Current.Request.UserHostAddress; LogErrors.LogedError(ex, ip); }
static Errors() { AccountErrors = new AccountErrors(); MaintenanceErrors = new MaintenanceErrors(); DatabaseErrors = new DatabaseErrors(); UserCreatorErrors = new UserCreatorErrors(); AuthErrors = new AuthErrors(); EmailErrors = new EmailErrors(); LogErrors = new LogErrors(); }
private void HandleNewClient(object client) { var tcpClient = (TcpClient)client; try { NetworkStream clientStream = tcpClient.GetStream(); using (var stream = new StreamReader(clientStream)) { //assume a continuous stream of JSON objects using (var reader = new JsonTextReader(stream) { SupportMultipleContent = true }) { while (reader.Read()) { if (CancelToken.IsCancellationRequested) { break; } try { JObject json = JObject.Load(reader); ApplyFilters(json); ProcessJson(json); Interlocked.Increment(ref _receivedMessages); } catch (Exception ex) { var jex1 = LogErrors.LogException("Bad Json", ex); if (jex1 != null) { ProcessJson(jex1); } LogManager.GetCurrentClassLogger().Warn(ex); Interlocked.Increment(ref _errorCount); } } } } } catch (OperationCanceledException) { } catch (Exception ex) { LogManager.GetCurrentClassLogger().Error(ex); } tcpClient.Close(); Finished(); }
public string DownloadWeatherXML() { try { string xml = new WebClient().DownloadString(_url); string modifiedxml = xml.Replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n", ""); return modifiedxml; } catch (Exception e) { LogErrors LogObj = new LogErrors(); LogObj.InsertErrors(e.Message, e.Source, e.StackTrace, e.TargetSite.ToString()); return null; } }
public string DownloadWeatherXML() { try { string xml = new WebClient().DownloadString(_url); string modifiedxml = xml.Replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n", ""); return(modifiedxml); } catch (Exception e) { LogErrors LogObj = new LogErrors(); LogObj.InsertErrors(e.Message, e.Source, e.StackTrace, e.TargetSite.ToString()); return(null); } }
/// <summary> /// Verifies the deployment model and waits till it reaches zero deployment errors. /// </summary> /// <param name="self"></param> /// <param name="configure">Builder infrastructure for the deployment model</param> /// <returns></returns> public static async Task VerifyDeploymentModelAsync(this Hub self, Action <DeploymentModelBuilder> configure) { if (self is null) { throw new ArgumentNullException(nameof(self)); } var model = BuildModel(configure); var awaitable = self.VerifyObservable(model) .Do(LogErrors(self)) .Where(x => x.Length == 0) .FirstAsync() .GetAwaiter(); var firstErors = model.Verify(self.Protocol); if (firstErors.Length > 0) { LogErrors(self)(firstErors); await awaitable; } }
public static void AddErrorInLog(string NameError, string DescrError) { try { using (AvtoritetEntities ae = new AvtoritetEntities()) { LogErrors log = new LogErrors(); string myHost = Dns.GetHostName(); string compIP = ""; for (int i = 0; i < Dns.GetHostEntry(myHost).AddressList.Length; i++) { if (!Dns.GetHostEntry(myHost).AddressList[i].IsIPv6LinkLocal) { if (compIP != "") { compIP += ", "; } compIP += Dns.GetHostEntry(myHost).AddressList[i].ToString(); } } string userNameWin = Environment.UserName; string compName = Environment.MachineName; log.Computer = string.Concat(new string[] { myHost, ", ", compIP, ", ", userNameWin, ", ", compName }); log.DateError = new DateTime?(DateTime.Now); log.ExeName = "Прокси сервер"; log.NameError = NameError; log.DescrError = DescrError; ae.LogErrors.Add(log); ae.SaveChanges(); } } catch { } }
/// <summary> /// Удалить /// </summary> /// <param name="ID"></param> /// <returns></returns> public LogErrors DeleteLogErrors(long ID) { LogErrors dbEntry = context.LogErrors.Find(ID); if (dbEntry != null) { try { context.LogErrors.Remove(dbEntry); context.SaveChanges(); } catch (Exception e) { e.SaveErrorMethod(String.Format("DeleteLogErrors(ID={0})", ID), blog); return(null); } } return(dbEntry); }
// This method calls a stored proc to insert the xml into a staging temp table public void InsertData(string XmlStrObj) { using (SqlConnection conn = new SqlConnection(_connstr)) { try { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "CheckAndInsertData"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@raw_xml", SqlDbType.Xml); cmd.Parameters["@raw_xml"].Value = XmlStrObj; cmd.Connection = conn; cmd.ExecuteNonQuery(); } catch (Exception e) { LogErrors LogObj = new LogErrors(); LogObj.InsertErrors(e.Message, e.Source, e.StackTrace, e.TargetSite.ToString()); } } }
public static bool DeployAssembly(string server, int port, string path, string cacheId, string depAsmPath, LogErrors logError) { List <FileInfo> files = new List <FileInfo>(); // List that will hold the files and subfiles in path string fileName = null; byte[] asmData; string failedNodes = string.Empty; Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = null; try { if (port != -1) { NCache.Port = port; } if (port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (server != null || server != string.Empty) { NCache.ServerName = server; } cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cacheServer != null) { serverConfig = cacheServer.GetNewConfiguration(cacheId); if (path != null && path != string.Empty) { if (Path.HasExtension(path)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(path); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) { files.Add(f); } } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed."); return(false); } } } if (depAsmPath != null && depAsmPath != string.Empty) { if (Path.HasExtension(depAsmPath)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(depAsmPath); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) { files.Add(f); } } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed."); return(false); } } } foreach (FileInfo f in files) { try { FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read); asmData = new byte[fs.Length]; fs.Read(asmData, 0, asmData.Length); fs.Flush(); fs.Close(); fileName = Path.GetFileName(f.FullName); if (serverConfig.CacheSettings.CacheType == "clustered-cache") { foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { NCache.ServerName = node.IpAddress.ToString(); try { cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); cacheServer.CopyAssemblies(cacheId, fileName, asmData); } catch (Exception ex) { logError("Failed to Deploy Assembly on " + NCache.ServerName); logError("Error Detail: " + ex.Message); } } } else { cacheServer.CopyAssemblies(cacheId, fileName, asmData); } } catch (Exception e) { string message = string.Format("Could not deploy assembly \"" + fileName + "\". {0}", e.Message); logError("Error : " + message); return(false); } } } } catch (Exception e) { logError("Error : {0}" + e.Message); } finally { NCache.Dispose(); } return(true); }
public static bool DeployAssembly(string server, int port, string path, string cacheId, string depAsmPath,LogErrors logError ) { List<FileInfo> files = new List<FileInfo>(); // List that will hold the files and subfiles in path string fileName=null; byte[] asmData; string failedNodes = string.Empty; Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = null; try { if (port != -1) { NCache.Port = port; } if (port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; if (server != null || server != string.Empty) { NCache.ServerName = server; } cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (cacheServer != null) { serverConfig = cacheServer.GetNewConfiguration(cacheId); if (path != null && path != string.Empty) { if (Path.HasExtension(path)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(path); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) files.Add(f); } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed!!!!"); return false; // We already got an error trying to access dir so dont try to access it again } } } if (depAsmPath != null && depAsmPath != string.Empty) { if (Path.HasExtension(depAsmPath)) { FileInfo fi = new FileInfo(path); files.Add(fi); } else { DirectoryInfo di = new DirectoryInfo(depAsmPath); try { foreach (FileInfo f in di.GetFiles("*")) { if (Path.HasExtension(f.FullName)) files.Add(f); } } catch (Exception ex) { logError("Directory " + di.FullName + "could not be accessed!!!!"); return false; // We already got an error trying to access dir so dont try to access it again } } } foreach (FileInfo f in files) { try { FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read); asmData = new byte[fs.Length]; fs.Read(asmData, 0, asmData.Length); fs.Flush(); fs.Close(); fileName = Path.GetFileName(f.FullName); if (serverConfig.CacheSettings.CacheType == "clustered-cache") { foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { NCache.ServerName = node.IpAddress.ToString(); try { cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); cacheServer.CopyAssemblies(cacheId, fileName, asmData); } catch (Exception ex) { logError("Failed to Deploy Assembly on "+NCache.ServerName); logError("Error Detail: "+ex.Message); } } } else cacheServer.CopyAssemblies(cacheId,fileName,asmData); } catch (Exception e) { string message = string.Format("Could not deploy assembly \"" + fileName + "\". {0}", e.Message); logError("Error : " + message); return false; } } } } catch (Exception e) { logError("Error : {0}" + e.Message); } finally { NCache.Dispose(); } return true; }
//Init constructor public CorporationController() { corporationRepo = new CorporationRepo(new Connection()); errors = new LogErrors(); }
//Init constructor public ForumController() { forumRepo = new ForumRepo(new Connection()); errors = new LogErrors(); }
//Init constructor public UserController() { userRepo = new UserRepo(new Connection()); errors = new LogErrors(); }
//Init constructor public ReactionController() { reactionRepo = new ReactionRepo(new Connection()); errors = new LogErrors(); }
//Init constructor public SoftwareController() { softwareRepo = new SoftwareRepo(new Connection()); errors = new LogErrors(); }
//Init constructor public MessageController() { messageRepo = new MessageRepo(new Connection(), new ReactionRepo(new Connection())); errors = new LogErrors(); }