예제 #1
0
 private static ITracer createTracer(Assembly assembly)
 {
     if (assembly == (Assembly)null)
         throw new ArgumentNullException(nameof(assembly));
     string traceFileName = GlobalTracer.getTraceFileName(assembly);
     int result;
     if (!int.TryParse(GlobalConfiguration.AppSettings["LogLevel"], out result))
         result = !GlobalConfiguration.Debug ? 2 : 4;
     ITracer tracer = (ITracer)new FileTracer(traceFileName)
     {
         LogLevel = result
     };
     if (GlobalConfiguration.GetBoolean("EnableServerLog") && GlobalConfiguration.CurrentSession != null && tracer is FileTracer)
         (tracer as FileTracer).ServerTracer = GlobalTracer.createServerTracer(GlobalConfiguration.CurrentSession, assembly);
     if (tracer == null)
         throw new Exception("Init tracer failed.");
     GlobalTracer.initTrace(tracer);
     try
     {
         tracer.Info(string.Format("The assembly:{0}, version:{1} was initialized.", (object)assembly.GetName().Name, (object)assembly.GetName().Version));
         tracer.Info(string.Format("The Utility4, version:{0} was loaded.", (object)typeof(GlobalTracer).Assembly.GetName().Version));
     }
     catch (Exception ex)
     {
     }
     return tracer;
 }
예제 #2
0
        public FileTracer(string traceFile, string messageFormat)
        {
            if (string.IsNullOrWhiteSpace(traceFile))
            {
                throw new ArgumentNullException(nameof(traceFile));
            }
            this.LogLevel    = 5;
            this.PopUpErrors = GlobalConfiguration.GetBoolean(nameof(PopUpErrors), false);
            int result1;

            if (!int.TryParse(GlobalConfiguration.AppSettings[nameof(MaxRetriesForFileLog)], out result1))
            {
                result1 = 5;
            }
            int result2;

            if (!int.TryParse(GlobalConfiguration.AppSettings[nameof(MilliSecBetweenFileLogRetries)], out result2))
            {
                result2 = 5000;
            }
            this.MaxRetriesForFileLog          = result1;
            this.MilliSecBetweenFileLogRetries = result2;
            this.init(traceFile, messageFormat);
            this.ServerTracer = (ServerTracer)null;
        }
예제 #3
0
 public static void TraceError(string message)
 {
     GlobalTracer.Instance.Error(message, GlobalTracer.GetClassName());
     if (!GlobalConfiguration.GetBoolean("LogErrorsToEventLog"))
         return;
     string source = GlobalConfiguration.AppSettings["EventLogSource"];
     if (string.IsNullOrEmpty(source))
         source = ".NET Runtime";
     try
     {
         if (!EventLog.SourceExists(source))
             EventLog.CreateEventSource(new EventSourceCreationData(source, GlobalTracer.GetLogName()));
     }
     catch (Exception ex)
     {
         source = ".NET Runtime";
     }
     EventLog.WriteEntry(source, string.Format("{0} ({1})", (object)message, (object)GlobalTracer.GetClassName()), EventLogEntryType.Error, 1026);
 }