/// <summary> /// Provides an NLog-Loggers to config using NLog.config file. /// </summary> /// <returns>The NLogLogger.</returns> protected override ILoggerFacade CreateLogger() { ILoggerFacade logger = new NLogLogger(); logger.Log("${SolutionName} Logger was created.", Category.Info, Priority.None); return logger; }
public void Setup() { // arrange - setup nlog LoggingConfiguration config = new LoggingConfiguration(); _memoryTarget = new MemoryTarget { Layout = @"${level} ${message}" }; config.AddTarget("memory", _memoryTarget); LoggingRule rule = new LoggingRule("*", LogLevel.Trace, _memoryTarget); config.LoggingRules.Add(rule); LogManager.Configuration = config; // arrange - setup logger _logger = new NLogLogger("memory"); }
private void GetLocationCollection() { try { using (Stream stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("VH.ViewModel.SupportingFiles.LocationDataBase.txt")) { if (stream != null) { using (var streamReader = new StreamReader(stream)) { var locationCollection = new Dictionary <string, string>(); string line; while ((line = streamReader.ReadLine()) != null) { var location = new Location().GetLocation(line); if (location != null) { if (!locationCollection.ContainsKey(location.CityName)) { locationCollection.Add(location.CityName, location.State); } } _weakRefLocationCollection = new WeakReference(locationCollection); } _weakRefCityCollection = new WeakReference(locationCollection.OrderBy(x => x.Key).Select(x => x.Key).Distinct().ToList()); _weakRefStateCollection = new WeakReference(locationCollection.OrderBy(x => x.Value).Select(x => x.Value).Distinct().ToList()); } } } } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
public void MultiThread_SimpleLogFile_Test() { MultiThreadTestsCaseRunner.ReportStartedTest(ThreadingType.MultiThreaded, LogFileType.SimpleFile); #region Log4net Log4NetLogger.ConfigureSimpleFileLogger(ThreadingType.MultiThreaded); MultiThreadTestsCaseRunner.Run( LoggingLib.Log4Net, LogFileType.SimpleFile, (runNr, logNr) => Log4NetLog.Info($"Run #{runNr} - Log #{logNr}")); Log4NetLogger.DisableLogger(); #endregion SleepBeforeNextTestCaseRun(); #region NLog NLogLogger.ConfigureSimpleFileLogger(ThreadingType.MultiThreaded); MultiThreadTestsCaseRunner.Run( LoggingLib.NLog, LogFileType.SimpleFile, (runNr, logNr) => NLogLog.Info($"Run #{runNr} - Log #{logNr}")); #endregion SleepBeforeNextTestCaseRun(); #region Serilog Serilog.Core.Logger serilogLogger = SerilogLogger.ConfigureSimpleFileLogger(ThreadingType.MultiThreaded); MultiThreadTestsCaseRunner.Run( LoggingLib.Serilog, LogFileType.SimpleFile, (runNr, logNr) => serilogLogger.Information($"Run #{runNr} - Log #{logNr}")); #endregion MultiThreadTestsCaseRunner.ReportTestResults(ThreadingType.MultiThreaded, LogFileType.SimpleFile); }
//get list public List <Article> SP_Article_GetList_CMS(int ArticleID, string Title, int MenuID, string Tags, int isHot, int Status, DateTime FromDate, DateTime ToDate, int Page, int PageSize, out int TotalRow) { try { var pars = new SqlParameter[11]; pars[0] = new SqlParameter("@ArticleID", ArticleID); pars[1] = new SqlParameter("@Title", Title); pars[2] = new SqlParameter("@MenuID", MenuID); pars[3] = new SqlParameter("@Tags", Tags); if (isHot == -1) { pars[4] = new SqlParameter("@isHot", DBNull.Value); } else if (isHot == 0) { pars[4] = new SqlParameter("@isHot", false); } else { pars[4] = new SqlParameter("@isHot", true); } pars[5] = new SqlParameter("@Status", Status); pars[6] = new SqlParameter("@FromDate", FromDate); pars[7] = new SqlParameter("@ToDate", ToDate); pars[8] = new SqlParameter("@Page", Page); pars[9] = new SqlParameter("@PageSize", PageSize); pars[10] = new SqlParameter("@TotalRow", SqlDbType.Int) { Direction = ParameterDirection.Output }; var list = new DBHelper(Config.Site1400ConnectionString).GetListSP <Article>("SP_Article_GetList_CMS", pars); TotalRow = Convert.ToInt32(pars[10].Value); return(list); } catch (Exception ex) { NLogLogger.LogInfo(ex.ToString()); TotalRow = 0; return(new List <Article>()); } }
private void OnUpdateRepairStatus() { try { var childVM = new UpdateCustomerRepairStatusViewModel(this.Messenger, this.UserLogin, this.Entity.InternalList.FirstOrDefault(x => x.IsSelected)) { ParentViewModel = this }; childVM.RefreshCustomerRepair += this.GetRefreshCustomerRepairCollection; var messageDailog = new VMMessageDailog() { ChildViewModel = childVM }; MessengerInstance.Send(messageDailog); } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
private void OnAddAppointment() { try { var childVM = new AppointmentViewModel(this.MessengerInstance, this.UserLogin, this.Entity.InternalList.FirstOrDefault(x => x.IsSelected)) { ParentViewModel = this.ParentViewModel }; var messageDailog = new VMMessageDailog() { ChildViewModel = childVM }; MessengerInstance.Send(messageDailog); } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
public override void OnAddItem() { try { var childVM = new AppointmentViewModel(this.Messenger, this.UserLogin, this.SelectedCustomer) { ParentViewModel = this }; childVM.RefreshCustomerAppointment += this.GetCustomerAppointments; var messageDailog = new VMMessageDailog() { ChildViewModel = childVM }; MessengerInstance.Send(messageDailog); } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
/// <summary> /// phân quyền chức năng cho danh sách user /// </summary> /// <param name="FunctionID"></param> /// <param name="ListRole"></param> /// <param name="CreateUserID"></param> /// <returns></returns> public int UserFunctionInsertListByFunctionID(int FunctionID, string ListRole, int CreateUserID) { try { var pars = new SqlParameter[4]; pars[0] = new SqlParameter("@_FunctionID", FunctionID); pars[1] = new SqlParameter("@_PermissionOfUsers", ListRole); pars[2] = new SqlParameter("@_CreatedUserID", CreateUserID); pars[3] = new SqlParameter("@_ResponseCode", SqlDbType.Int) { Direction = ParameterDirection.Output }; new DBHelper(Config.Site1400ConnectionString).ExecuteNonQuerySP("SP_UserFunction_InsertList_byFunctionID", pars); return(Convert.ToInt32(pars[3].Value)); } catch (Exception ex) { NLogLogger.LogInfo(ex.ToString()); return(-99); } }
public override void OnAddItem() { try { var childVM = new AddCallLogViewModel(this.Messenger, this.UserLogin) { ParentViewModel = this }; childVM.RefreshCallRegistry += this.GetCallRegisterCollectionByDate; var messageDailog = new VMMessageDailog() { ChildViewModel = childVM }; MessengerInstance.Send(messageDailog); } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
private void OnAddCustomer() { try { var childVM = new AddCustomerViewModel(this.Messenger, this.UserLogin) { ParentViewModel = this }; childVM.RefreshCustomers += this.GetCustomerCollection; var messageDailog = new VMMessageDailog() { ChildViewModel = childVM }; MessengerInstance.Send(messageDailog); } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
public static void Main(string[] args) { ILogger logger = new NLogLogger("logs.txt"); AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { logger.Error("Unhandled exception " + eventArgs.ExceptionObject?.ToString()); Console.ReadLine(); // TODO: remove later }; try { IRunnerApp runner = new RunnerApp(logger); runner.Run(args); } catch (Exception e) { logger.Error("Runner exception", e); Console.ReadLine(); // TODO: remove later } }
public void SP_Suggestion_Create(string Email, string Mobile, string Suggestion, out int ResponseStatus) { try { var pars = new SqlParameter[4]; pars[0] = new SqlParameter("@Email", Email); pars[1] = new SqlParameter("@Mobile", Mobile); pars[2] = new SqlParameter("@Suggestion", Suggestion); pars[3] = new SqlParameter("@ResponseStatus", SqlDbType.Int) { Direction = ParameterDirection.Output }; new DBHelper(Config.Site1400ConnectionString).ExecuteNonQuerySP("SP_Suggestion_Create", pars); ResponseStatus = Convert.ToInt32(pars[3].Value); } catch (Exception ex) { NLogLogger.LogInfo(ex.ToString()); ResponseStatus = -99; } }
public List<AdvertModel> SP_Advert_GetList(int PostID, int Type, int Status) { try { var pars = new SqlParameter[] { new SqlParameter("@_PostID", PostID), new SqlParameter("@_Type", Type), new SqlParameter("@_Status", Status) }; var list = db.GetListSP<AdvertModel>("SP_Advert_GetList", pars); NLogLogger.Info(JsonConvert.SerializeObject(list)); return list; } catch (Exception ex) { NLogLogger.Exception(ex); return new List<AdvertModel>(); } }
public IcssAdapter(IProgressConnection connection) : base(connection) { try { this.proxyAppObject = new ICProxyAppObject(connection.Connection); this.pdsContext = new pdsContextDataSet(); this.dataSet = new pdsicssDataSet() { DataSetName = DataSetName }; this.icssTableControlKey = this.dataSet.ttblicss.GetTableControlParametersKey(); if (!this.tempTableControlParameters.ContainsKey(this.icssTableControlKey)) { this.CreateTableControlParameters(this.icssTableControlKey); } this.OnCreated(); } catch (Exception ex) { NLogLogger.ErrorException("Failed in adapter ", ex); ErrorReportingHelper.ReportProgramErrors($"Error in IcssAdapter constructor - {ex.Message}"); } }
public static bool CheckSign(string data, string sign) { try { X509Certificate2 certificate = new X509Certificate2(ConfigurationManager.AppSettings["KeyMapPath"]); RSACryptoServiceProvider rsacp = new RSACryptoServiceProvider(); string publicKey = certificate.PublicKey.Key.ToXmlString(false); rsacp.FromXmlString(publicKey); byte[] verify = Encoding.UTF8.GetBytes(data); NLogLogger.Info(string.Format("\r\n{0}\r\n{1}", data, sign)); byte[] signature = Convert.FromBase64String(sign); return(rsacp.VerifyData(verify, "SHA1", signature)); } catch (Exception ex) { NLogLogger.Info(string.Format("{0}\r\n{1}\r\n{2}", ConfigurationManager.AppSettings["KeyMapPath"], data, sign)); NLogLogger.Info(ex.ToString()); return(false); } }
public virtual bool IsSigned() { try { //this.Get(); NLogLogger.LogInfo(this._UserName + " - " + this._ClientIP + " - " + this._IsExpires); bool bLoged = (this._UserName.Length > 0 && this._ClientIP.Length > 0 && !this._IsExpires); if (bLoged) { this.SetCookieUserInfo(this._UserId, this._UserName, this._IsAdministrator, this._SessionID); } return(bLoged); } catch (Exception ex) { NLogLogger.PublishException(ex); SignOut(); return(false); } }
public void OnAddHearingAIDItem() { try { var childVM = new AddCustomerHearingAidOrderViewModel(this.Messenger, this.UserLogin, this.Entity) { ParentViewModel = this }; childVM.RefreshCustomerHearingAIDOrder += this.RefreshCustomerHearingAidOrderCollection; var messageDailog = new VMMessageDailog() { ChildViewModel = childVM }; MessengerInstance.Send(messageDailog); } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
static void Main(string[] args) { ConfigureNLog(); NLogLogger.Use(); var bus = CreateBus(); bus.Start(); try { var address = new Uri("rabbitmq://localhost/request_service"); var client = bus.CreateRequestClient <ISimpleRequest, ISimpleResponse>(address, TimeSpan.FromSeconds(10)); for (;;) { Console.Write("Enter customer id (quit exits): "); string customerId = Console.ReadLine(); if (customerId == "quit") { break; } // this is run as a Task to avoid weird console application issues Task.Run(() => { var response = client.Request(new SimpleRequest(customerId)).Result; Console.WriteLine("Customer Name: {0}", response.CustomerName); }).Wait(); } } catch (Exception e) { //throw; Console.WriteLine("OMG! {0}", e); } finally { bus.Stop(); } }
public static bool AddCustomerWarrantyInformed(string connectionString, CustomerWarrantyInformed customerWarrantyInformed) { try { using (var context = new CustomerDBContext(connectionString)) { var cloneObject = customerWarrantyInformed.CreateAClone(); cloneObject.ApplyCurrentDateTime(); context.CustomerWarrantyInformeds.Add(cloneObject); var result = context.SaveChanges(); return(result > 0); } } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); return(false); } return(false); }
static void Main(string[] args) { NLogLogger.Use(); ILog log = Logger.Get <Program>(); var localXmlFilePath = Environment.CurrentDirectory + @"\\XmlConfiguration\\ActorConfiguration.xml"; var localXmlFileActorConfiguration = LocalXmlFileActorConfiguration.Load(localXmlFilePath); var localXmlFileActorDirectory = new LocalXmlFileActorDirectory(localXmlFileActorConfiguration); var localActor = new RpcActor(localXmlFileActorConfiguration); var helloClient = RpcServiceProxyGenerator.CreateServiceProxy <IHelloService>(localActor, "server"); var calcClient = RpcServiceProxyGenerator.CreateServiceProxy <ICalcService>(localActor, "server"); localActor.RegisterRpcService(helloClient as RpcService); localActor.RegisterRpcService(calcClient as RpcService); localActor.Bootup(localXmlFileActorDirectory); var container = new TestContainer(); container.AddModule(new TestModule(helloClient, calcClient)); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container); string uri = "http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); Console.WriteLine("Server is listening on [{0}].", uri); Console.WriteLine("Type something to stop ..."); Console.ReadKey(); host.Stop(); Console.WriteLine("Stopped. Goodbye!"); }
public static bool DeleteCustomer(string connectionString, Customer customer) { try { using (var context = new CustomerDBContext(connectionString)) { context.Customers.Attach(new Customer() { ID = customer.ID }); context.Customers.Remove(customer); var result = context.SaveChanges(); return(result > 0); } } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); return(false); } }
protected TestFixture(string solutionRelativeTargetProjectParentDir) { var startupAssembly = typeof(TStartup).GetTypeInfo().Assembly; var builder = new WebHostBuilder() .UseStartup(typeof(TStartup)) .ConfigureServices(InitializeServices) .ConfigureAppConfiguration((hostContext, config) => { config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); config.AddJsonFile("customSettings.json", optional: true, reloadOnChange: true); config.AddJsonFile("patreonTokens.json", optional: true, reloadOnChange: true); }); server = new TestServer(builder); Client = server.CreateClient(); Client.BaseAddress = new Uri("http://localhost"); Database.Instance = new Database(Startup.Configuration.GetSection(nameof(AppSettings.DatabaseConString)).Value); NLogLogger.ConfigureLogger(); LogManager.Init(new NLogLogProvider()); }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { ILogger logger = new NLogLogger("logs.txt"); if (eventArgs.ExceptionObject is Exception e) { logger.Error(FailureString, e); } else { logger.Error(FailureString + eventArgs.ExceptionObject?.ToString()); } }; try { IRunnerApp runner = new RunnerApp(); runner.Run(args); return; } catch (AggregateException e) { ILogger logger = new NLogLogger("logs.txt"); logger.Error(FailureString, e.InnerException); } catch (Exception e) { ILogger logger = new NLogLogger("logs.txt"); logger.Error(FailureString, e); } finally { NLogLogger.Shutdown(); } Console.WriteLine("Press RETURN to exit."); Console.ReadLine(); }
public List <Menu> SP_Menu_GetByUrlRedirect(string UrlRedirect) { try { var pars = new SqlParameter[1]; pars[0] = new SqlParameter("@UrlRedirect", UrlRedirect); var list = new DBHelper(Config.Site1400ConnectionString).GetListSP <Menu>("SP_Menu_GetByUrlRedirect", pars); if (list != null || list.Count >= 0) { return(list); } else { return(null); } } catch (Exception ex) { NLogLogger.LogInfo(ex.ToString()); return(null); } }
public int SP_Article_UpdateStatus_CMS(int ArticleID, int Status, string CreateUser) { try { var pars = new SqlParameter[4]; pars[0] = new SqlParameter("@ArticleID", ArticleID); pars[1] = new SqlParameter("@Status", Status); pars[2] = new SqlParameter("@CreateUser", CreateUser); pars[3] = new SqlParameter("@ResponseStatus", DbType.Int32) { Direction = ParameterDirection.Output }; db.ExecuteNonQuerySP("SP_Article_UpdateStatus_CMS", pars); return(Convert.ToInt32(pars[3].Value)); } catch (Exception ex) { NLogLogger.Exception(ex); return(-99); } }
public static bool DeleteAppointment(string connectionString, Appointment appointment) { try { using (var context = new AppointmentDBContext(connectionString)) { context.Appointments.Attach(new Appointment() { ID = appointment.ID }); context.Appointments.Remove(appointment); var result = context.SaveChanges(); return(result > 0); } } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); return(false); } }
public List <EventGiftCode> SP_CMS_Event_GetList(string EventName, int EventValue, string Staff, string Fromdate, string Todate, int TypeSelect = 0) { var lst = new List <EventGiftCode>(); try { var pars = new SqlParameter[] { new SqlParameter("@_TypeSelect", TypeSelect), new SqlParameter("@_EventName", EventName), new SqlParameter("@_EventValue", EventValue), new SqlParameter("@_Staff", Staff), new SqlParameter("@_Fromdate", Fromdate), new SqlParameter("@_Todate", Todate) }; lst = db.GetListSP <EventGiftCode>("SP_CMS_Event_GetList", pars); } catch (Exception e) { NLogLogger.Exception(e); } return(lst); }
public static bool DeleteUserLogin(string connectionString, UserLogin userLogin) { try { using (var context = new UserLoginDBContext(connectionString)) { context.UserLogins.Attach(new UserLogin() { ID = userLogin.ID }); context.UserLogins.Remove(userLogin); var result = context.SaveChanges(); return(result > 0); } } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); return(false); } }
public List <GiftCodeModel> SP_GiftCode_GetList(string GiftcodeName, int GiftcodeValue, int Status, string FromDate, string ToDate) { var lst = new List <GiftCodeModel>(); try { var pars = new SqlParameter[] { new SqlParameter("@_GiftCodeName", GiftcodeName), new SqlParameter("@_GiftCodeValue", GiftcodeValue), new SqlParameter("@_Status", Status), new SqlParameter("@_FromDate", FromDate), new SqlParameter("@_ToDate", ToDate), }; lst = db.GetListSP <GiftCodeModel>("SP_GiftCode_GetList", pars); } catch (Exception e) { NLogLogger.Exception(e); } return(lst); }
private void PropertyChangedCapture() { try { this.Entity.PropertyChanged += (sender, args) => { if (args.PropertyName == "AppointmentDate") { Task.Factory.StartNew(() => { var item = (Appointment)sender; this.GetReminders(item.AppointmentDate); }); } }; } catch (Exception exception) { NLogLogger.LogError(exception, TitleResources.Error, ExceptionResources.ExceptionOccured, ExceptionResources.ExceptionOccuredLogDetail); } }
/// <summary> /// Xóa UserLog /// </summary> /// <param name="fromDate"></param> /// <param name="toDate"></param> /// <param name="userId"></param> /// <param name="functionId"></param> /// <param name="paygateName"></param> /// <returns></returns> public int DeleteUsersLog(string fromDate, string toDate, int userId, int functionId) { try { var pars = new SqlParameter[5]; pars[0] = new SqlParameter("@_Fromdate", fromDate); pars[1] = new SqlParameter("@_Todate", toDate); pars[2] = new SqlParameter("@_UserID", userId); pars[3] = new SqlParameter("@_FunctionID", functionId); pars[4] = new SqlParameter("@_ResponseCode", SqlDbType.Int) { Direction = ParameterDirection.Output }; new DBHelper(Config.Site1400ConnectionString).ExecuteNonQuerySP("SP_UserLogs_Delete", pars); return(Convert.ToInt32(pars[4].Value)); } catch (Exception ex) { NLogLogger.LogInfo(ex.ToString()); return(-99); } }
public void Cleanup() { _logger = null; _memoryTarget.Dispose(); }
static GlobalLogger() { Logger = new NLogLogger(); }