static void http_OnLogAccess(object sender, LogAccessEventArgs e) { LogAccess data = e.Data; Console.WriteLine(data.Date + "\t" + data.ClientIP + "\t" + data.Method + "\t" + data.RawUrl); Console.WriteLine(data.UserAgent); Console.WriteLine("------------------------------------------------------------"); }
public LogModule() : base("Log") { Get["/"] = x => View["Grid"]; Post["/PostQuery"] = r => { QueryCondition condition = this.Bind <QueryCondition>(); return(Response.AsJson(LogAccess.Query(condition))); }; }
public void GetNullLoggerTest() { Logger first, second; first = LogAccess.GetNullLogger(); second = LogAccess.GetNullLogger(); Assert.IsNotNull(first); Assert.IsNotNull(second); Assert.AreEqual(first, second); TryLogger(first); }
public void GetLoggerTest() { string Category1 = "Some cat"; string Category2 = "Another cat"; Logger first, second, third, nullLog; first = LogAccess.GetLogger(Category1); second = LogAccess.GetLogger(Category2); third = LogAccess.GetLogger(Category1); nullLog = LogAccess.GetNullLogger(); Assert.IsNotNull(first); Assert.IsNotNull(second); Assert.AreNotEqual(first, nullLog); Assert.AreNotEqual(second, nullLog); Assert.AreNotEqual(first, second); Assert.AreEqual(first, third); TryLogger(first); }
static void Main(string[] args) { LogAccess.GetLogger("main"); int parse; if (args.Length >= 2) { if (int.TryParse(args[0], out parse)) { if (parse > 0) { threadCount = parse; } } if (int.TryParse(args[1], out parse)) { if (parse > 0) { messageCount = parse; } } } Console.WriteLine("Regular test"); Console.WriteLine("Elapsed {0} miliseconds\n", runThreads(CountFlood)); if (args.Length < 3) { Thread.Sleep(5000); //Console.WriteLine("ID test"); //LogAccess.FilterAddID(3); //Console.WriteLine("Elapsed {0} miliseconds\n", runThreads(IdFlood)); Console.WriteLine("Nlog test"); Console.WriteLine("Elapsed {0} miliseconds\n", runThreads(NlogFlood)); Console.ReadKey(); } }
static void Main(string[] args) { string pwd = Directory.GetCurrentDirectory(); string dbName = "LoggerTest"; CreateSqlDatabase(pwd, dbName); string connectionString = string.Format(@"Data Source=(LocalDb)\v11.0;Initial Catalog={0};AttachDBFilename={1}\{2}.mdf" , dbName, pwd, dbName); IOptions options = new Options(connectionString, dbName + ".dbo.LogOptions", OptionsReaderType.Database); options["LogWriteTarget"] = "Database"; options["LogConnectionString"] = connectionString; options["LogWriteTable"] = dbName + ".dbo.LogOutput"; options["LogDaysToKeep"] = "1"; LogAccess.Init(options); options.Save(); var logger = LogAccess.GetLogger("alogger"); for (int n = 0; n < 30; n++) { try { Console.Write(submain(0)); } catch (Exception ex) { logger.Error("happy error", ex); } } for (int n = 0; n < 10000; n++) { logger.Info("info" + n, new int[] { n, 2, 3 }); } Console.ReadKey(); }
private void WriteLogFalse(string type, Exception e) { LogAccess.Write_Exp(type + e + GetLogContent()); }
private void WriteLog(string type) { LogAccess.Write(type + GetLogContent()); }
protected override void WriteDeleteProtectedLog(string type) { LogAccess.Write(type + GetLogContent() + '\t' + "该部门下还有员工"); }
protected override void WriteDeleteProtectedLog(string type) { LogAccess.Write(type + GetLogContent() + '\t' + "该员工存该月存在打卡记录,不能删除"); }
public static int Delete(DateTime keepDate) { return(LogAccess.Delete(keepDate)); }
public static Page <Sys_Log> GetList(long pageIndex, long pageSize, DateTime limitDate, string keyWord, string level) { return(LogAccess.GetList(pageIndex, pageSize, limitDate, keyWord, level)); }
protected override void WriteDeleteProtectedLog(string type) { LogAccess.Write("该宿舍还有成员"); }
protected override void WriteDeleteProtectedLog(string type) { LogAccess.Write("该岗位还有员工,无法删除"); }
/// <summary> /// Insert New Access /// </summary> /// <param name="userAdmin"></param> /// <param name="userIp"></param> /// <param name="date"></param> /// <returns></returns> public Message InsertNewAccess(string stSession, string userAdmin, string userIp) { Message msg = null; try { LogAccess myLog = new LogAccess(); myLog.Id = Guid.NewGuid(); myLog.SessionId = stSession; myLog.UserIp = userIp; myLog.UserAdmin = userAdmin; myLog.DatetimeAccess = DateTime.Now; dbContext.LogAccesses.InsertOnSubmit(myLog); dbContext.SubmitChanges(); // success message msg = new Message(MessageConstants.I0001, MessageType.Info, "Log access", "added"); } catch { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }