private void PrintMessage(string message, Color color) { try { if (!IsDebug) { return; } if (LogPlace.InvokeRequired) { LogPlace.Invoke(new MethodInvoker(() => { SetDataToRichTextBox(LogPlace, message, color); })); } else { SetDataToRichTextBox(LogPlace, message, color); } ConsoleHistory.Add(message); LogCount++; } catch (Exception e) { Console.WriteLine(e); } }
public static void Write(ncelsEntities context, LogPlace place, Guid?employeeId, string text, string additionalText = null, bool withoutIp = false) { string ipAddress = ""; if (withoutIp == false) { try { ipAddress = HttpContext.Current.Request.UserHostAddress; } catch (Exception ex) { ipAddress = "ошибка получения: " + ex.Message; if (ipAddress.Length > 1000) { ipAddress = ipAddress.Substring(0, 1000); } } } var lg = new ActionLog(); lg.Date = DateTime.Now; lg.EmployeeId = employeeId; lg.PlaceId = (int)place; lg.Text = text; lg.Type = 1; lg.AdditionalText = additionalText; lg.IpAddress = ipAddress; context.ActionLogs.Add(lg); }
public static void Write(LogPlace place, Guid?employeeId, string text, string additionalText = null) { ncelsEntities context = UserHelper.GetCn(); Write(context, place, employeeId, text, additionalText); context.SaveChanges(); }
/// <summary> /// 日別のログファイルの位置を取得 /// </summary> /// <param name="date">日付</param> /// <returns>ログファイル位置</returns> LogPlace GetLogFilePlace(DateTime date) { var lp = new LogPlace(); lp.YMDir = Path.Combine(this.LogRootDirPath, date.ToString("yyyyMM")); lp.File = string.Concat(this.Prefix, date.ToString("yyyyMMdd"), this.Ext); lp.FullPath = Path.Combine(lp.YMDir, lp.File); return(lp); }
/// <summary> /// 拡張ログデータファイルの位置を取得 /// </summary> /// <param name="prefix2">ファイル名に付与される2番目のプレフィックス</param> /// <param name="ext">ファイルの拡張子</param> /// <param name="date">日付</param> /// <returns>ログファイル位置</returns> LogPlace GetExLogFilePlace(string prefix2, string ext, DateTime date) { prefix2 = string.IsNullOrEmpty(prefix2) ? "ex" : string.Concat(prefix2, "."); var lp = new LogPlace(); lp.YMDir = Path.Combine(this.LogRootDirPath, date.ToString("yyyyMM")); lp.File = string.Concat(this.Prefix, prefix2, date.ToString("yyyyMMdd.mmssff"), ext); lp.FullPath = Path.Combine(lp.YMDir, lp.File); return(lp); }
public void Log(string str, LogPlace logPlace, string fileName, bool includeDetails) { lock (logLock) { if (logPlace == LogPlace.File || logPlace == LogPlace.FileAndEventLog) WriteToFile(str, fileName, includeDetails); if (logPlace == LogPlace.EventLog || logPlace == LogPlace.FileAndEventLog) WriteToEventLog(str); } }
/// <summary> /// ログファイル出力先ディレクトリを作成する /// </summary> /// <param name="lp">ログファイル位置</param> void CreateDirectory(LogPlace lp) { // ルートフォルダが無かったら作成する if (!Directory.Exists(this.LogRootDirPath)) { Directory.CreateDirectory(this.LogRootDirPath); } // 年月フォルダが無かったら作成する if (!Directory.Exists(lp.YMDir)) { Directory.CreateDirectory(lp.YMDir); } }
public Logger(LogPlace logPlace) { logLock = new object(); FileInfo fi = new FileInfo(Assembly.GetEntryAssembly().Location); DefaultLogFileName = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".log"; eventLog = new EventLog(); eventLog.Log = "Application"; eventLog.Source = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length); DefaultLogPlace = logPlace; }