Esempio n. 1
0
        private void btnTestLog_Click(object sender, EventArgs e)
        {
            NLogUtility.InfoLog("test message", "prefix", "subDir");
            NLogUtility.DebugLog("debug message", "prefix", "subDir");
            Exception ex = null;

            try
            {
                TestEx();
            }
            catch (Exception ex1)
            {
                ex = ex1;
            }

            NLogUtility.ExceptionLog(ex, "prefix", "subDir", "extInfo");
            Dictionary <string, object> dictVariable = new Dictionary <string, object>();

            //NLogUtility.CallInfoLog(DateTime.Now.AddMinutes(-1), DateTime.Now, 100010, "127.0.0.1", dictVariable, "call message");
            dictVariable.Add("Action", "action");
            dictVariable.Add("ProductId", "product");
            dictVariable.Add("CallSource", "callSource");
            dictVariable.Add("SessionId", "sessionId");
            dictVariable.Add("SessionState", 1);
            dictVariable.Add("UserId", 100000);
            dictVariable.Add("UserName", "UserName");
            dictVariable.Add("ResultCode", 0);
            NLogUtility.CallInfoLog(DateTime.Now.AddMinutes(-1), DateTime.Now, dictVariable, "call message");
            //NLogUtility.CallErrorLog(100010, DateTime.Now.AddMinutes(-1), DateTime.Now, "action", "callSource", "127.0.0.1", "sessionId", 1, 100000, "UserName", 0, ex, "ext message");
            NLogUtility.CallErrorLog(DateTime.Now.AddMinutes(-1), DateTime.Now, dictVariable, ex, "ext message");
        }
Esempio n. 2
0
 /// <summary>
 /// 监视的文件发生改变
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnWatcherChanged(object sender, FileSystemEventArgs e)
 {
     lock (this)
     {
         FileSystemWatcher watcher = (FileSystemWatcher)sender;
         NLogUtility.InfoLog(string.Format("文件已变更({0}): {1}\\{2}", e.ChangeType, watcher.Path, watcher.Filter), "OnWatcherChanged", "MultiFileWatcher");
         if (OnChange != null)
         {
             OnChange(sender, e);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 监视一个文件
        /// </summary>
        /// <param name="fileName"></param>
        public void Watch(string fileName)
        {
            FileSystemWatcher watcher = new FileSystemWatcher()
            {
                Path                = Path.GetDirectoryName(fileName),
                Filter              = Path.GetFileName(fileName),
                NotifyFilter        = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.Size | NotifyFilters.Security | NotifyFilters.Attributes, /* 开始监视*/
                EnableRaisingEvents = true
            };

            watcher.Created += OnWatcherChanged;
            watcher.Changed += OnWatcherChanged;
            watcher.Deleted += OnWatcherChanged;
            NLogUtility.InfoLog(string.Format("监视文件: {0}\\{1}", watcher.Path, watcher.Filter), "Watch", "MultiFileWatcher");

            lock (this)
            {
                _watchers.Add(watcher);
            }
        }