private static void ExportData <T>(bool confirmExport) { if (!confirmExport) { return; } string prefix = typeof(T).Name; ILogger logger = new TextFileLogger(prefix, 10000000, true); if (prefix == "Bar") { logger.Log("<TICKER>,<PER>,<DATE>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>"); foreach (Bar item in TradingData.Instance.Get <IEnumerable <Bar> >().OrderBy(i => i.DateTime)) { logger.Log(item.ToFinamString()); } } else { foreach (T item in TradingData.Instance.Get <IEnumerable <T> >()) { logger.Log(item.ToString()); } } }
public void TextFileLoggerCanLog() { string msgText = "text file logger test"; string expected = String.Empty; string actual = String.Empty; Message msg = new GeneralMessage(msgText); StubFileFactory fileFactory = new StubFileFactory("dummy.txt"); TextFileLogger txtlogger = new TextFileLogger(fileFactory); using (MemoryStream ms = fileFactory.MemoryStream) { txtlogger.Log(msg); ms.Position = 0; using (StreamReader reader = new StreamReader(ms, Encoding.UTF8)) { actual = reader.ReadToEnd(); } } expected = DateTime.Now.ToShortDateString() + " " + msgText + Environment.NewLine; Assert.AreEqual(expected, actual); }
public static string GetEmailContentToXmlByNode(string fileName, string node) { TextFileLogger log = new TextFileLogger(); try { XmlDocument oXmlDoc = new XmlDocument(); // oXmlDoc.Load(SF.Framework.SFConfig.WebsitePhysicalPath + "/Content/EmailTemplate/" + fileName); //AppDomain.CurrentDomain.BaseDirectory string path = ""; if (System.Web.HttpContext.Current != null) { path = System.Web.HttpContext.Current.Server.MapPath("~/Content/EmailTemplate/" + fileName); } else { path = ConfigurationManager.AppSettings["WebsitePath"] + "/Content/EmailTemplate/" + fileName; } oXmlDoc.Load(path); XmlNode oNode = oXmlDoc.SelectSingleNode("/emails/email[position()=1]"); string body = oNode.SelectSingleNode(node).InnerText; return(body); } catch (Exception ex) { log.Log(ex); return(""); } }
public void Common_Create_New_File_On_Size_Limit_Exceed() { TextFileLogger logger = new TextFileLogger("log", 10000); for (int i = 0; i < 200; i++) { logger.Log(String.Format("{0}, Запись в журнале", DateTime.Now)); } Assert.IsTrue(File.Exists("log-0.log")); FileInfo fileInfo = new FileInfo("log-0.log"); Assert.IsTrue(fileInfo.Length > 10000); Assert.IsTrue(File.Exists("log-1.log")); StreamReader streamReader = new StreamReader(new FileStream("log-1.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); Assert.IsTrue(streamReader.ReadLine().Contains("Запись в журнале")); streamReader.Close(); streamReader.Dispose(); logger.Dispose(); }
protected override void OnStartup(StartupEventArgs e) { try { var config = ApplicationConfiguration.FromJsonFile(_configFilename); IEyeTracker eyeTracker = null; switch (config.EyeTrackerName.ToUpper()) { case "TOBII4C": eyeTracker = new TobiiEyeTracker4C(); break; default: throw new NotImplementedException($"Eye tracker {config.EyeTrackerName} not supported"); } var logger = new TextFileLogger(); App.Current.DispatcherUnhandledException += (sender, ev) => { #if DEBUG ev.Handled = true; #endif logger.Log(ev.Exception); }; var overlays = new List <IOverlay>(); overlays.Add(new PositionOverlay()); var window = new MainWindow(config, eyeTracker, logger, overlays); window.Show(); } catch (Exception exception) { throw new StartupException("Initialization error", exception); } }
private void LogLinks(string log) { if (String.IsNullOrEmpty(log)) { return; } TextFileLogger.Log(Settings.InterstingURLs, DateTime.Now.ToString("yyyy-MM-dd") + ".txt", log); }
public void OnlyTracesAboveEnableLevelAreLogged() { var mockFileSystem = new MockFileSystem(); var logger = new TextFileLogger(LogLevel.Information, _filePath, mockFileSystem); logger.Log(LogLevel.Debug, _logMessage); logger.Log(LogLevel.Critical, _logMessage); var logFile = mockFileSystem.GetFile(_filePath); var fileContents = logFile.TextContents.ToLower(); Assert.IsTrue( fileContents.Contains($"{LogLevel.Critical.ToString().ToLower()}: {_logMessage}")); Assert.IsFalse( fileContents.Contains($"{LogLevel.Debug.ToString().ToLower()}: {_logMessage}")); }
public static void ExportData <T>(string prefix, IEnumerable <T> data) { //string prefix = typeof(T).Name; ILogger logger = new TextFileLogger(prefix, 10000000, true); foreach (T item in data) { logger.Log(item.ToString()); } }
public static void ExportData <T>(bool confirmExport) { if (!confirmExport) { return; } string prefix = typeof(T).Name; ILogger logger = new TextFileLogger(prefix, 10000000, true); if (prefix == "Bar") { //logger.Log("<TICKER>,<PER>,<DATE>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>"); //logger.Log("<TICKER>,<PER>,<DATE>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<DATEID>"); logger.Log(Bar.ToStringHeader()); foreach (Bar item in TradingData.Instance.Get <IEnumerable <Bar> >().OrderBy(i => i.DateTime)) { //logger.Log(item.ToStringFinam()); logger.Log(item.ToStringShort()); } } else if (prefix == "Tick") { logger.Log(Tick.ToStringHeader()); foreach (Tick item in TradingData.Instance.Get <IEnumerable <Tick> >().OrderBy(i => i.DateTime)) { logger.Log(item.ToStringShort()); } } else { ///TODO 1. ExportData<T> Добавить BarDateId foreach (T item in TradingData.Instance.Get <IEnumerable <T> >()) { logger.Log(item.ToString()); } } }
public int SaveChanges() { try { int i = this.CurrentDbContext.SaveChanges(); return(i); } catch (Exception dbEx) { TextFileLogger log = new TextFileLogger(); log.Log(dbEx); return(0); } }
static public void HandleException(System.Exception ex, string message = "An errror occured in LBF Video Lib", bool ignoreException = true) { // Format the exception message. ExceptionFormatter formater = new ExceptionFormatter(); string formatedException = formater.Format(message, ex); // Log error message in production category. // If severity is critical then it also send error to config mail address. TextFileLogger.Log(formatedException, ErrorLogFileName); if (!ignoreException) { throw ex; } }
public void TraceLogWritesToTextFile(LogLevel logLevel) { var mockFileSystem = new MockFileSystem(); var logger = new TextFileLogger(LogLevel.Trace, _filePath, mockFileSystem); logger.Log(logLevel, _logMessage); var logFile = mockFileSystem.GetFile(_filePath); var fileContents = logFile.TextContents.ToLower(); Assert.IsTrue(logLevel == LogLevel.None ? fileContents.Contains($"{_logMessage}") : fileContents.Contains($"{logLevel.ToString().ToLower()}: {_logMessage}")); }
private static void ExportData <T>(bool confirmExport) { if (!confirmExport) { return; } string prefix = typeof(T).Name; ILogger logger = new TextFileLogger(prefix, 10000000); foreach (T item in TradingData.Instance.Get <IEnumerable <T> >()) { logger.Log(item.ToString()); } }
private static void LogRequest(HttpWebRequest request, WebPageRequest webRequest) { List <string> nontransferableHeaders = new List <string>() { "Content-Type", "Referer" }; StringBuilder sb = new StringBuilder(); sb.Append(request.Method); sb.Append(" "); sb.Append(request.Address); sb.Append(Environment.NewLine); sb.Append("Content-Type: "); sb.Append(request.ContentType); sb.Append(Environment.NewLine); sb.Append("Referer: "); sb.Append(request.Referer); sb.Append(Environment.NewLine); for (int i = 0; i < request.Headers.Count; ++i) { string header = request.Headers.GetKey(i); if (nontransferableHeaders.Contains(header)) { continue; } foreach (string value in request.Headers.GetValues(i)) { sb.Append(header); sb.Append(": "); sb.Append(value); sb.Append(Environment.NewLine); } } sb.Append("Content-Length:"); sb.Append(request.ContentLength); sb.Append(Environment.NewLine); TextFileLogger.Log(webRequest.LogDir, "HTTPRequests-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now + Environment.NewLine + sb.ToString()); }
private void frmLogin_Load(object sender, EventArgs e) { try { label11.Location = new System.Drawing.Point(panel4.Width / 2 - 150, 11); label2.Location = new System.Drawing.Point(panel4.Width / 2 - 75, 15); this.progressBar1.Visible = true; this.progressBar1.Enabled = true; this.progressBar1.Value = 10; //ClientHelper.GetClientThumbanailPath(); _clientInfoFilePath = ClientHelper.GetClientInfoFilePath(); if (!File.Exists(_clientInfoFilePath)) { MessageBox.Show("Invalid Configuration", "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } this.progressBar1.Value = 30; CommonAppStateDataHelper.ClientInfoObject = Cryptograph.DecryptObject <ClientInfo>(_clientInfoFilePath); _clientInfo = CommonAppStateDataHelper.ClientInfoObject; this.progressBar1.Value = 70; if (_clientInfo != null) { lblSessionYears.Text = ClientHelper.GetSessionString(_clientInfo.SessionString); lblSchoolWelcome.Text = ClientHelper.GetWelcomeString(_clientInfo.SchoolName, _clientInfo.SchoolCity, _clientInfo.SchoolId); lblExpireDate.Text = ClientHelper.GetExpiryDateString(_clientInfo.SessionEndDate); _currentMacAddress = MacAddressHelper.GetMacAddress(); //_currentMacAddress = "B82A72A780B7"; _firebaseRegInfo = GetFirebaseRegistrationInformation(); string errorMessage = ""; bool deleteVideos = false; bool skipLoginScreen = false; // Check license session duraion LicenseValidationState licenseState = ValidateLicenseNew(_firebaseRegInfo, _clientInfo, _currentMacAddress, out errorMessage, out deleteVideos, out skipLoginScreen); TextFileLogger.Log("License State" + licenseState.ToString()); if (licenseState != LicenseValidationState.Valid) { OnAfterLicesseValidation(errorMessage, deleteVideos, licenseState); } _showLoginForm = !skipLoginScreen; this.progressBar1.Value = 100; //// update mac address in local client info file //if (licenseState == LicenseValidationState.Valid) //{ // this.progressBar1.Value = 90; // //if (string.IsNullOrEmpty(CommonAppStateDataHelper.ClientInfoObject.MacAddress)) // //{ // // _showLoginForm = true; // //} // //else // //{ // // _showLoginForm = false; // //} //} //else //{ // this.progressBar1.Value = 100; // Application.Exit(); //} } else { throw new Exception("Invalid client info configuration."); } } catch (Exception ex) { ExceptionHandler.HandleException(ex); MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Log(string log) { TextFileLogger.Log(Settings.LogDir, DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now + "-" + log); }