示例#1
0
        private static void FatalError()
        {
            string msg = String.Format(Messages.MESSAGEBOX_PROGRAM_UNEXPECTED,
                                       HelpersGUI.DateTimeToString(DateTime.Now, "yyyy-MM-dd HH:mm:ss", false), GetLogFile_());

            log.Fatal(msg + "\n" + Environment.StackTrace);
            MainWindow m = Program.MainWindow;

            if (m == null)
            {
                log.Fatal("Program.MainWindow is null");
            }
            else
            {
                log.FatalFormat("Program.MainWindow.Visible == {0}", m.Visible);
                log.FatalFormat("Program.MainWindow.InvokeRequired == {0}", m.InvokeRequired);
                log.FatalFormat("CurrentThread.Name == {0}", Thread.CurrentThread.Name);
            }

            if (RunInAutomatedTestMode)
            {
                if (TestExceptionString == null)
                {
                    TestExceptionString = msg + "\n" + Environment.StackTrace;
                }
            }
            else
            {
                new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Error, msg, Messages.MESSAGEBOX_PROGRAM_UNEXPECTED_TITLE)).ShowDialog();
            }
        }
示例#2
0
 public void FatalFormat(string format, params object[] args)
 {
     if (IsFatalEnabled)
     {
         loger.FatalFormat(format, args);
     }
 }
示例#3
0
        private static List <Type> GetPluginTypes(string pluginFile, Type type)
        {
            try
            {
                System.Reflection.Assembly assembly = null;
                string typeName = string.Empty;


                if (File.Exists(pluginFile))
                {
                    assembly = System.Reflection.Assembly.LoadFile(pluginFile);
                }
                else
                {
                    log.FatalFormat("Plugin file {0} not found", pluginFile);
                    return(null);
                }

                if (assembly != null)
                {
                    List <Type> list = assembly.GetTypes().ToList()
                                       .Where(p => p.IsSubclassOf(type)).ToList();

                    return(list);
                }
            }
            catch (System.BadImageFormatException)
            {
                log.FatalFormat("The Assembly is invalid--it is not a valid .NET Assembly file");
            }

            return(new List <Type>());
        }
示例#4
0
 public void FatalFormat(string format, object arg0)
 {
     if (log != null)
     {
         log.FatalFormat(format, arg0);
     }
 }
示例#5
0
 public void FatalFormat(string format, params object[] args)
 {
     _logger.FatalFormat(format, args);
     if (_createNewIfOutOfScope())
     {
         _scopedLogger.Value.LogCritical(format, args);
     }
 }
 public void FatalFormat(string format, Object obj)
 {
     if (log.IsFatalEnabled)
     {
         format = string.Concat(Enumerable.Repeat(indent, indentLevel)) + format;
         log.FatalFormat(format, obj);
     }
 }
示例#7
0
        public void FatalWithFormat(string format, params object[] args)
        {
            var info = args[0] as LocationInfo;

            if (info != null)
            {
                _log.FatalFormat(format, args);
            }
            else
            {
                _log.FatalFormat(GetLocationInfo() + "\r\nMsg: " + format, args);
            }
        }
示例#8
0
 public void Fatal(string message, params object[] args)
 {
     if (_log.IsFatalEnabled)
     {
         _log.FatalFormat(message, args);
     }
 }
示例#9
0
        protected void Application_Error(Object sender, EventArgs e)
        {
            log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            Exception ex = null;


            if ((ex = Server.GetLastError()) != null)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
            }

            var loginUser = Session[Constant.SESSION_LOGIN_USER] as LoginUser;

            if (loginUser != null)
            {
                logger.FatalFormat("Company code: [{0}]; Logged in user: [{1}]", loginUser.CompanyCode, loginUser.UserAccount);
            }
            if (ex != null)
            {
                logger.Fatal(Messages.E999, ex);
            }
            else
            {
                logger.Fatal(Messages.E999);
            }

            Response.Redirect("/Error/");
        }
示例#10
0
        /// <summary>
        /// The log samples.
        /// </summary>
        private static void LogSamples()
        {
            // The global context is shared by all threads in the current AppDomain. This context is thread
            // safe for use by multiple threads concurrently.  We can create these as needed and add these
            // into layout pattern or have the ability to remove from the conversionPattern.
            // https://logging.apache.org/log4net/release/manual/contexts.html
            // Adding these into the conversionPattern _-> %property{EntityName} and  %property{AllocatedBytes}
            log4net.GlobalContext.Properties["EntityName"]     = EntityName;
            log4net.GlobalContext.Properties["AllocatedBytes"] = new StructuredMessage.GcAllocatedBytesHelper();

            Logger.Info(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));
            Logger.InfoFormat(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));

            Logger.Debug(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));
            Logger.DebugFormat(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));

            Logger.Error(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));
            Logger.ErrorFormat(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));

            Logger.Fatal(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));
            Logger.FatalFormat(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));

            Logger.Warn(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));
            Logger.WarnFormat(MyLogMessage.GetMessage(Guid.NewGuid().ToString(), "LogSamples"));
        }
示例#11
0
        void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Error);
                log.FatalFormat("{0} : Archiving Failed : {1}", DateTime.Now.ToString("h:mm:ss tt"), e.Error.Message);
                MessageBox.Show(string.Format("Archiving Failed" + Environment.NewLine + e.Error.Message), "Zip", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            else if (e.Cancelled)
            {
                TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
                log.WarnFormat("{0} : Archiving Cancelled", DateTime.Now.ToString("h:mm:ss tt"));
                MessageBox.Show("Archiving Cancelled", "Zip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Close();
            }
            else
            {
                timer.Stop();

                log.InfoFormat("{0} : Archiving Success", DateTime.Now.ToString("h:mm:ss tt"));
                //MessageBox.Show("Archiving Success", "Zip", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MessageBox.Show(String.Format("Archiving Success. Time Elapsed = {0}", timer.ElapsedMilliseconds), "Zip", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }
示例#12
0
        public void Log(Grillisoft.FastCgi.LogLevel level, string format, params object[] args)
        {
            switch (level)
            {
            case Grillisoft.FastCgi.LogLevel.Critical:
                _logger.FatalFormat(format, args);
                break;

            case Grillisoft.FastCgi.LogLevel.Error:
                _logger.ErrorFormat(format, args);
                break;

            case Grillisoft.FastCgi.LogLevel.Warning:
                _logger.WarnFormat(format, args);
                break;

            case Grillisoft.FastCgi.LogLevel.Info:
                _logger.InfoFormat(format, args);
                break;

            case Grillisoft.FastCgi.LogLevel.Verbose:
                _logger.DebugFormat(format, args);
                break;

            default:
                break;
            }
        }
示例#13
0
        static void Main(string[] args)
        {
            using (LogProvider.OpenNestedContext("AlikaPosConsole_MAIN"))
            {
                log.Info("Starting AlikaPosConsole Application");

                Console.WriteLine("Press enter key to exit");
                Console.WriteLine();

                using (IScanner scanner = CreateScanner(args.Length == 0))
                {
                    try
                    {
                        log.InfoFormat("Activate hardware event subscriber [{0}]", scanner);
                        scanner.Activate();
                        Console.WriteLine(scanner);
                        Console.WriteLine("Scan documents now");
                        Console.ReadLine();
                    }
                    catch (Exception e)
                    {
                        log.FatalFormat("Failure to activate subscriber [{0}] exception [{1}]", scanner, e);
                    }
                }

                log.Info("Terminating AlikaPosConsole Application");
            }
        }
示例#14
0
        /// <summary>
        /// 输出普通日志
        /// </summary>
        /// <param name="level"></param>
        /// <param name="format"></param>
        /// <param name="args"></param>
        private void Log(LogLevel level, string format, params object[] args)
        {
            switch (level)
            {
            case LogLevel.Debug:
                _Logger4net.DebugFormat(format, args);
                break;

            case LogLevel.Info:
                _Logger4net.InfoFormat(format, args);
                break;

            case LogLevel.Warn:
                _Logger4net.WarnFormat(format, args);
                break;

            case LogLevel.Error:
                _Logger4net.ErrorFormat(format, args);
                break;

            case LogLevel.Fatal:
                _Logger4net.FatalFormat(format, args);
                break;
            }
        }
示例#15
0
 public static void FatalFormatted(string format, params object[] args)
 {
     if ((int)Parameter.LogLevel <= (int)LogLevelEnum.Fatal)
     {
         log.FatalFormat(format, args);
     }
 }
示例#16
0
        void OnDatabaseMessage(DatabaseMessage message)
        {
            try
            {
                switch (message.Action)
                {
                case DatabaseMessage.ActionType.Add:
                    if (message.Application != null)
                    {
                        Add(message.Application);
                    }
                    else if (message.Tab != null)
                    {
                        Add(message.Tab);
                    }
                    break;

                case DatabaseMessage.ActionType.Remove:
                    if (message.Application != null)
                    {
                        Remove(message.Application);
                    }
                    else if (message.Tab != null)
                    {
                        Remove(message.Tab);
                    }
                    break;

                case DatabaseMessage.ActionType.Update:
                    if (message.Application != null)
                    {
                        Update(message.Application);
                    }
                    else if (message.Tab != null)
                    {
                        Update(message.Tab);
                    }
                    break;

                case DatabaseMessage.ActionType.Move:
                    if (message.Tab != null && message.TabB != null)
                    {
                        Move(message.Tab, message.TabB);
                    }
                    break;

                case DatabaseMessage.ActionType.Save:
                    DoSave();
                    break;
                }

                // Save changes.
                Save();
            }
            catch (Exception ex)
            {
                Log.FatalFormat("Database exception {0}", ex);
            }
        }
示例#17
0
        /// <summary>
        /// 处理要更新到server的tag数据
        /// </summary>
        /// <param name="dic">键是tag和ServerHandle,值是要更新的tag值的字典</param>
        protected void updateDataToOPCServer(IDictionary <int, object> dic)
        {
            if (null == dic || dic.Count == 0)
            {
                return;
            }
            var keylist = dic.Keys.ToList();

            keylist.Insert(0, 0);   //因为下标从1开始,开始插入空的
            var valuelist = dic.Values.ToList();

            valuelist.Insert(0, null);   //因为下标从1开始,开始插入空的

            var ArrServerHandle = (Array)keylist.ToArray();
            var ArrLocalValue = (Array)valuelist.ToArray();
            var ArrError = (Array) new Int32[dic.Count];
            int a, b;

            a = DateTime.Now.Millisecond;
            b = a;

            var opcresult = new OpcUpdateResult(new AutoResetEvent(false));

            this.updateTransactionIDDic.AddOrUpdate(transactionID, opcresult, (aa, bb) => opcresult);
            log.DebugFormat("批量更新OPC的值此次更新{0}条数据,更新编号是{1}", dic.Count, transactionID);
            _opcGroup.AsyncWrite(dic.Count, ref ArrServerHandle, ref ArrLocalValue, out ArrError, transactionID++, out b);
            //等待更新到opc服务器的更新结果,这里因受DCOM影响,最长时间可能需要6分钟才有结果
            //但中间有可能存在opc重连接的情况,不能死等因此需要设最大值6分钟,
            if (opcresult.autoEvent.WaitOne(TimeSpan.FromMinutes(0.2D)))
            {
                if (opcresult.result.All(x => x))
                {
                    log.DebugFormat("更新OPC的值更新编号{0},结果全部成功", transactionID);
                }
                else
                {
                    log.FatalFormat("更新OPC的值更新编号{0},有{1}项失败", transactionID, opcresult.result.Count(x => !x));
                }
            }
            else
            {
                log.FatalFormat("更新OPC的值更新编号{0},6分钟内结果无反馈", transactionID);
            }
            opcresult.Dispose();
        }
示例#18
0
        public void LogThings()
        {
            const string format = "This is a [{0}] level logging event";

            log.DebugFormat(format, "Debug");
            log.InfoFormat(format, "Info");
            log.WarnFormat(format, "Warn");
            log.ErrorFormat(format, "Error");
            log.FatalFormat(format, "Fatal");
        }
示例#19
0
 /// <summary>
 /// 记录程序致命格式化消息
 /// </summary>
 /// <param name="format"></param>
 /// <param name="args"></param>
 public void FatalFormat(string format, params object[] args)
 {
     if (_log.IsFatalEnabled)
     {
         _log.FatalFormat(format, args);
     }
     else
     {
         DiagnosticsFormat(format, args);
     }
 }
        public void LoggingExtensions_Test1()
        {
            log.DebugFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.InfoFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.WarnFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.ErrorFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.FatalFormat("Time now is {0:S}", DateTime.Now.ToString());

            log.TraceFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.VerboseFormat("Time now is {0:S}", DateTime.Now.ToString());
        }
示例#21
0
        public static Type getOPCTypeByVarType(short Enumeration)
        {
            switch (Enumeration)
            {
            case 3:
                //long
                return(typeof(long));

            case 2:
                //long
                return(typeof(short));

            case 5:
                //double
                return(typeof(double));

            case 7:
                //date
                return(typeof(DateTime));

            case 18:
                //word bcd
                return(typeof(int));

            case 16:
                //char
                return(typeof(byte));

            case 17:
                //byte
                return(typeof(byte));

            case 11:
                //Boolean
                return(typeof(bool));

            case 4:
                return(typeof(float));

            case 8:
                //string
                return(typeof(string));

            case 19:
                //dword lbcd
                return(typeof(Int64));

            default:
                log.FatalFormat("没有定义类型{0}", Enumeration);
                Console.WriteLine("有未知的tag类型");
                throw new NotImplementedException("未知类型");
            }
        }
        public static void LogThings()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(OtherLogger));

            const string format = "This is a [{0}] level logging event";

            log.DebugFormat(format, "Debug");
            log.InfoFormat(format, "Info");
            log.WarnFormat(format, "Warn");
            log.ErrorFormat(format, "Error");
            log.FatalFormat(format, "Fatal");
        }
示例#23
0
文件: Program.cs 项目: 00mjk/xenadmin
        private static void FatalError()
        {
            string msg = String.Format(Messages.MESSAGEBOX_PROGRAM_UNEXPECTED,
                                       HelpersGUI.DateTimeToString(DateTime.Now, "yyyy-MM-dd HH:mm:ss", false), GetLogFile());

            var msgWithStackTrace = string.Format("{0}\n{1}", msg, Environment.StackTrace);

            log.Fatal(msgWithStackTrace);

            MainWindow m = MainWindow;

            if (m == null)
            {
                log.Fatal("Program.MainWindow is null");
            }
            else
            {
                log.FatalFormat("Program.MainWindow.Visible == {0}", m.Visible);
                log.FatalFormat("Program.MainWindow.InvokeRequired == {0}", m.InvokeRequired);
                log.FatalFormat("CurrentThread.Name == {0}", Thread.CurrentThread.Name);
            }

            if (RunInAutomatedTestMode)
            {
                if (TestExceptionString == null)
                {
                    TestExceptionString = msgWithStackTrace;
                }
            }
            else
            {
                using (var dlg = new ErrorDialog(msg)
                {
                    WindowTitle = Messages.MESSAGEBOX_PROGRAM_UNEXPECTED_TITLE
                })
                    dlg.ShowDialog();
            }
        }
示例#24
0
        private void GetPluginType()
        {
            try
            {
                Type t = AppDomain.CurrentDomain.GetAssemblies().ToList()
                         .SelectMany(s => s.GetTypes())
                         .Where(p => p.FullName == this.TypeName).FirstOrDefault();

                PluginType = t != null ? t : null;
            }
            catch (System.BadImageFormatException)
            {
                log.FatalFormat("The Assembly is invalid--it is not a valid .NET Assembly file");
            }
        }
示例#25
0
        static void Main()
        {
            const string format = "This is a [{0}] level logging event";

            log.DebugFormat(format, "Debug");
            log.InfoFormat(format, "Info");
            log.WarnFormat(format, "Warn");
            log.ErrorFormat(format, "Error");
            log.FatalFormat(format, "Fatal");

            var logger = new OtherLogger();

            logger.LogThings();

            Console.ReadLine();
        }
示例#26
0
        static void Main()
        {
            log4net.Config.XmlConfigurator.Configure();
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));

            const string format = "This is a [{0}] level logging event";

            log.DebugFormat(format, "Debug");
            log.InfoFormat(format, "Info");
            log.WarnFormat(format, "Warn");
            log.ErrorFormat(format, "Error");
            log.FatalFormat(format, "Fatal");

            OtherLogger.LogThings();

            Console.ReadLine();
        }
示例#27
0
 static void Main(string[] args)
 {
     log4net.Config.XmlConfigurator.Configure();
     log4net.ILog log = log4net.LogManager.GetLogger("test");
     while (true)
     {
         log.ErrorFormat("{0} test error!", "henryfan");
         System.Threading.Thread.Sleep(5000);
         log.InfoFormat("{0} test Info!", "henryfan");
         System.Threading.Thread.Sleep(5000);
         log.DebugFormat("{0} test Info!", "henryfan");
         System.Threading.Thread.Sleep(5000);
         log.FatalFormat("{0} test Info!", "henryfan");
         System.Threading.Thread.Sleep(5000);
     }
     Console.Read();
 }
示例#28
0
        /// <summary>
        /// Processes the specified request.
        /// </summary>
        /// <param name="context">The request context.</param>
        public void ProcessRequest(HttpContext context)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            ILocationExporter exporter;
            HttpResponse      response    = context.Response;
            string            format      = context.Request.QueryString["format"];
            string            disposition = context.Request.QueryString["disposition"];

            _log.InfoFormat("running, format={0}, disposition={1}", format, disposition);
            try {
                if ((exporter = GetExporter(format)) != null)
                {
                    response.ContentType = exporter.MimeType;
                    if ("attachment".Equals(disposition, StringComparison.Ordinal))
                    {
                        response.AddHeader("Content-Disposition",
                                           string.Format("attachment; filename=\"RcMap-Locations{0}\"",
                                                         exporter.FileExtension));
                    }
                    exporter.Export(LocationRepository.FindAll(), response.Output);
                }
                else
                {
                    response.ContentType = "text/plain";
                    response.Output.WriteLine(string.Format(
                                                  Messages.LocationExporterHandler_InvalidFormat, format));
                }
            } catch (Exception exc) {
                if (ExceptionHelper.IsFatal(exc))
                {
                    throw;
                }
                _log.FatalFormat("error running exporter, format={0}\r\n{1}", format, exc);
            } finally {
                _log.Info("complete");
            }
        }
示例#29
0
        /// <summary>
        ///  This method is called when has exception occur
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnException(ExceptionContext filterContext)
        {
            if (filterContext != null)
            {
                var loginUser = GetLoginUser();

                if (loginUser != null)
                {
                    logger.FatalFormat("Company code: [{0}]; Logged in user: [{1}]", loginUser.CompanyCode, loginUser.UserAccount);
                }

                logger.Fatal(Messages.E999, filterContext.Exception);
            }

            base.OnException(filterContext);

            if (!filterContext.HttpContext.Request.IsAjaxRequest() && filterContext.Exception != null)
            {
                this.Response.Redirect("/Error");
            }
        }
示例#30
0
        public void Fatal(Activity activity, string format, params object[] args)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }

            if (string.IsNullOrWhiteSpace(format))
            {
                throw new ArgumentNullException("format");
            }

            SetActivity(activity);

            if (args != null && args.Length > 0)
            {
                _logger.FatalFormat(CultureInfo.InvariantCulture, format, args);
            }
            else
            {
                _logger.Fatal(format);
            }
        }