示例#1
0
 static Log()
 {
     _TraceSwitchDebugUI = new TraceSwitch("TraceSwitchDebugUI", "Debug de operações na interface");
     _TraceSwitchDebugNg = new TraceSwitch("TraceSwitchDebugNg", "Debug de qualquer operação que não se enquadre no padrão interface");
     _TraceSwitchDebugBiblioteca = new TraceSwitch("TraceSwitchDebugBiblioteca", "Debug de operação em biblioteca");
     _TraceSwitchGeral = new TraceSwitch("TraceSwitchGeral", "Trace de negocio e dados");
 }
 internal static void Trace(TraceSwitch traceSwitch, string message)
 {
     if (traceSwitch != null)
     {
         Debug.WriteLine(traceSwitch.DisplayName + ": " + message);
     }
 }
 protected DbConnectionPoolCounters(string categoryName, string categoryHelp)
 {
     AppDomain.CurrentDomain.DomainUnload += new EventHandler(this.UnloadEventHandler);
     AppDomain.CurrentDomain.ProcessExit += new EventHandler(this.ExitEventHandler);
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.ExceptionEventHandler);
     string instanceName = null;
     if (!System.Data.Common.ADP.IsEmpty(categoryName) && System.Data.Common.ADP.IsPlatformNT5)
     {
         instanceName = this.GetInstanceName();
     }
     string str2 = categoryName;
     this.HardConnectsPerSecond = new Counter(str2, instanceName, CreationData.HardConnectsPerSecond.CounterName, CreationData.HardConnectsPerSecond.CounterType);
     this.HardDisconnectsPerSecond = new Counter(str2, instanceName, CreationData.HardDisconnectsPerSecond.CounterName, CreationData.HardDisconnectsPerSecond.CounterType);
     this.NumberOfNonPooledConnections = new Counter(str2, instanceName, CreationData.NumberOfNonPooledConnections.CounterName, CreationData.NumberOfNonPooledConnections.CounterType);
     this.NumberOfPooledConnections = new Counter(str2, instanceName, CreationData.NumberOfPooledConnections.CounterName, CreationData.NumberOfPooledConnections.CounterType);
     this.NumberOfActiveConnectionPoolGroups = new Counter(str2, instanceName, CreationData.NumberOfActiveConnectionPoolGroups.CounterName, CreationData.NumberOfActiveConnectionPoolGroups.CounterType);
     this.NumberOfInactiveConnectionPoolGroups = new Counter(str2, instanceName, CreationData.NumberOfInactiveConnectionPoolGroups.CounterName, CreationData.NumberOfInactiveConnectionPoolGroups.CounterType);
     this.NumberOfActiveConnectionPools = new Counter(str2, instanceName, CreationData.NumberOfActiveConnectionPools.CounterName, CreationData.NumberOfActiveConnectionPools.CounterType);
     this.NumberOfInactiveConnectionPools = new Counter(str2, instanceName, CreationData.NumberOfInactiveConnectionPools.CounterName, CreationData.NumberOfInactiveConnectionPools.CounterType);
     this.NumberOfStasisConnections = new Counter(str2, instanceName, CreationData.NumberOfStasisConnections.CounterName, CreationData.NumberOfStasisConnections.CounterType);
     this.NumberOfReclaimedConnections = new Counter(str2, instanceName, CreationData.NumberOfReclaimedConnections.CounterName, CreationData.NumberOfReclaimedConnections.CounterType);
     string str3 = null;
     if (!System.Data.Common.ADP.IsEmpty(categoryName))
     {
         TraceSwitch switch2 = new TraceSwitch("ConnectionPoolPerformanceCounterDetail", "level of detail to track with connection pool performance counters");
         if (TraceLevel.Verbose == switch2.Level)
         {
             str3 = categoryName;
         }
     }
     this.SoftConnectsPerSecond = new Counter(str3, instanceName, CreationData.SoftConnectsPerSecond.CounterName, CreationData.SoftConnectsPerSecond.CounterType);
     this.SoftDisconnectsPerSecond = new Counter(str3, instanceName, CreationData.SoftDisconnectsPerSecond.CounterName, CreationData.SoftDisconnectsPerSecond.CounterType);
     this.NumberOfActiveConnections = new Counter(str3, instanceName, CreationData.NumberOfActiveConnections.CounterName, CreationData.NumberOfActiveConnections.CounterType);
     this.NumberOfFreeConnections = new Counter(str3, instanceName, CreationData.NumberOfFreeConnections.CounterName, CreationData.NumberOfFreeConnections.CounterType);
 }
示例#4
0
 /// <summary>
 /// A constructor.
 /// </summary>
 public LoggerBase(string filename, System.Diagnostics.TraceLevel level, string eventSource)
 {
     this.FileName = filename;
     traceSwitch = new System.Diagnostics.TraceSwitch(string.Empty, string.Empty);
     traceSwitch.Level = level;
     this.eventSource = eventSource;
 }
示例#5
0
        /// <summary>
        /// Compare the trace levels to determine whether the trace statement will be logged.
        /// </summary>
        /// <param name="logCategory">Switch name (which is the same as the ACA.NET Logging category name)</param>
        /// <param name="tracingLevel">Level of the trace as defined by the trace statement in code</param>
        /// <returns>Whether the statement can be logged</returns>
        public static bool isLoggable(Category logCategory, int tracingLevel)
        {
            bool traceStatus = false;
            int switchLevel = 0;

            // Create an instance of the trace switch
            TraceSwitch mySwitch = new TraceSwitch(logCategory.ToString(), "");

            // If valid, grab the level
            if (mySwitch != null)
                switchLevel = TracingLevel(mySwitch.Level);
            //else
            //    throw new ConfigurationException(ERROR_CONFIGURATION_MISSING_SWITCH);

            // Compare the levels if valid
            if (switchLevel > 0)
            {
                if (switchLevel >= tracingLevel)
                    traceStatus = true; // Minimal tracing level met
            }
            // Tracing is off, disable logging
            else
                traceStatus = true;

            return traceStatus;
        }
        static Log()
        {
            Enabled = true;
            ShowAll = false;
            try
            {
                traceSwitch = new TraceSwitch("GatewaySwitch", "Configuration level for the gateway trace level.");
                traceSource = new TraceSource("GatewaySource");
            }
            catch
            {
            }

            try
            {
            // ReSharper disable UnusedVariable
                int v = (int)traceSwitch.Level;
            // ReSharper restore UnusedVariable
            }
            catch
            {
                traceSwitch = null;
            }

            // Cache all the event types (enumerate the TraceEventType and store it inside a dictionary)
            foreach (TraceEventType i in Enum.GetValues(typeof(TraceEventType)))
            {
                // Due to the debug window
                if(i == TraceEventType.Critical || i == TraceEventType.Error || i == TraceEventType.Start || i == TraceEventType.Stop)
                    cachedWillDisplay.Add(i,true);
                else
                    cachedWillDisplay.Add(i, CalcWillDisplay(i));
            }
        }
示例#7
0
文件: Logger.cs 项目: odinhaus/Suffuz
        static Logger()
        {
            TraceSwitch ts = new TraceSwitch("TraceLevelSwitch", "Determines the tracing level to log/display");
            TraceLevel = ts.Level;

            if (!EventLog.Exists("CSGO"))
            {
                EventLog.CreateEventSource(LOG_SOURCE, LOG_NAME);
            }

            try
            {
                _eventLog = new EventLog();
                _eventLog.Source = LOG_SOURCE;
                _eventLog.Log = LOG_NAME;
            }
            catch { }
            try
            {
                _eventLog.MaximumKilobytes = 200 * 1024;
                _eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0);
            }
            catch
            {
            }
            Trace.Listeners.Clear();
            Trace.Listeners.Add(new EventLogTraceListener(_eventLog)); // writes to EventLog
            Trace.Listeners.Add(new ConsoleTraceListener(true)); // writes to Console window
            Trace.Listeners.Add(new DefaultTraceListener()); // writes to Output window
        }
        static void Main()
        {
            if (!EventLog.SourceExists("SelfMailer"))
            {
                EventLog.CreateEventSource("SelfMailer", "Mes applications");
            }
            EventLog eventLog = new EventLog("Mes applications", ".", "SelfMailer");
            eventLog.WriteEntry("Mon message", EventLogEntryType.Warning);

            BooleanSwitch booleanSwitch = new BooleanSwitch("BooleanSwitch", "Commutateur booléen.");
            TraceSwitch traceSwitch = new TraceSwitch("TraceSwitch", "Commutateur complexe.");

            TextWriterTraceListener textListener = new TextWriterTraceListener(@".\Trace.txt");
            Trace.Listeners.Add(textListener);

            Trace.AutoFlush = true;
            Trace.WriteLineIf(booleanSwitch.Enabled, "Démarrage de l'application SelfMailer");

            Project = new Library.Project();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Forms.Main());

            Trace.WriteLineIf(traceSwitch.TraceInfo, "Arrêt de l'application SelfMailer");
        }
示例#9
0
文件: Log.cs 项目: HaKDMoDz/Irelia
 static Log()
 {
     TraceSwitch = new TraceSwitch(category, "Trace switch for irelia engine")
     {
         Level = TraceLevel.Verbose
     };
 }
示例#10
0
        public static bool decomp(Stream as_in, Stream as_out, bool ab_trace = false)
        {
            bool b_result = false;
            ts_trace = new TraceSwitch("TOLibSwitch", "Switch for message in TOLib");

            if (ab_trace)
                ts_trace.Level = TraceLevel.Verbose;
            else
                ts_trace.Level = TraceLevel.Error;

            try
            {
                using (BinaryReader br_file = new BinaryReader(as_in, Encoding.ASCII, true))
                {
                    byte mode = br_file.ReadByte();

                    if (mode == 0 || mode == 1 || mode == 3)
                    {
                        b_result = decompFile(br_file, as_out, mode);
                        if (!b_result)
                            throw new Exception("An error has occurred during decompression.");
                    }
                    else
                        throw new Exception("It's not a correct compression file.");
                }

                return true;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message + Environment.NewLine, "ERROR");
                return false;
            }
        }
示例#11
0
	    /// <summary>
		/// Initializes the trace/error loggers.
		/// </summary>
		public static void StartLogging(string dllName)
		{
            DllName = dllName;
			string defaultTraceLevel;
			string debugTraceLevel = String.Empty;
			try
			{
				defaultTraceLevel = Utility.GetappSetting("DefaultTracelevel");
				debugTraceLevel = Utility.GetappSetting("DebugTraceLevel");
			}
			catch (CheckedException)
			{
				defaultTraceLevel = "Info";
			}
			GetTraceLevel = new TraceSwitch("General", "The Output level of tracing");
			DebugLevel = new TraceSwitch("Debug", "The Output Debuglevel of tracing");
			// define the datastore for application specific files
			
			string applicationPath;
			//dllName = Assembly.GetExecutingAssembly().Location;
			applicationPath = Path.GetDirectoryName(dllName);
            if (applicationPath.ToUpperInvariant().Contains(@"C:\WINDOWS\MICROSOFT.NET"))
                applicationPath = Utility.HomePath;
			Debug.WriteLine(applicationPath);

			// Create Directory if it doesn't exists
			Directory.CreateDirectory(applicationPath);
			Directory.CreateDirectory(Path.Combine(applicationPath, "log"));
			// define the logging destination
			string shortName = Assembly.GetExecutingAssembly().Location;
			AppName = Path.GetFileNameWithoutExtension(shortName);
			string traceFile = Path.Combine(applicationPath, string.Format(CultureInfo.InvariantCulture,"log\\{0} Trace.log", AppName));
			GetErrorFile = Path.Combine(applicationPath, string.Format(CultureInfo.InvariantCulture,"log\\{0} Error.log", AppName));

			Debug.WriteLine(traceFile);
			Console.WriteLine("traceFile = " + traceFile);
			if (GetTraceLevel.Level == TraceLevel.Off || GetTraceLevel.Level == TraceLevel.Error
			    || GetTraceLevel.Level == TraceLevel.Warning)				
			{
				Console.WriteLine("TraceLevel set to default.");
				Debug.WriteLine("TraceLevel set to default.");

				GetTraceLevel = new TraceSwitch("General", "The Output level of tracing", defaultTraceLevel);
				DebugLevel = new TraceSwitch("Debug", "The Output Debuglevel of tracing", debugTraceLevel);
				//if (m_generalLevel.TraceInfo) InitTraceLog(traceFile);//write application tracing messages.

				GetLogFile = null;
				GetErrorFile = null;

				InitTraceLog(traceFile);
			}
			else
			{
				// Use custom logfile and TraceListener if info or verbose was set.
				Console.WriteLine("TraceLevel set to info or lower.");
				InitTraceLog(traceFile);
			}
			//CheckTraceLevels();
		}
示例#12
0
 public static void TraceInformation(TraceSwitch traceSwitch, string information)
 {
     ValidateArgumentIsNull(traceSwitch);
     if (traceSwitch.TraceInfo)
     {
         Trace.TraceInformation(information);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:OutputWindowTraceListener"/> class.
        /// </summary>
        /// <param name="outputWindow">The output window.</param>
        /// <param name="traceSwitch">The trace switch.</param>
        public OutputWindowTraceListener(IOutputWindowService outputWindow, TraceSwitch traceSwitch)
        {
            Guard.ArgumentNotNull(outputWindow, "outputWindow");
            Guard.ArgumentNotNull(traceSwitch, "traceSwitch");

            this.traceSwitch = traceSwitch;
            this.outputWindowService = outputWindow;
        }
 static EventLogger()
 {
     myTraceSwitch = new TraceSwitch("OptecLogger", "Trace logging for Optec Inc. FocusLynx");
     // Set to Verbose by default. Main application should set this to the desired level at runtime.
     myTraceSwitch.Level = TraceLevel.Verbose;
     SetupEventLogTraceListener();
     Trace.WriteLine("Optec EventLogger Initialized - Trace Level = " + LoggingLevel.ToString());
 }
示例#15
0
 static LogHelp()
 {
     var lister = new TextWriterTraceListener(HttpRuntime.AppDomainAppPath + "staticHtml_log.txt");
     lister.TraceOutputOptions = TraceOptions.DateTime;
     Trace.Listeners.Add(lister);
     Trace.AutoFlush = true;
     ts = new TraceSwitch("staticHtml", "staticHtml 日志开关", "2");
 }
示例#16
0
 /// <summary>
 /// A constructor.
 /// </summary>
 public LoggerBase(string filename, string switchName, string eventSource)
 {
     this.FileName = filename;
     switchName = string.IsNullOrEmpty(switchName) ? String.Empty : switchName;
     traceSwitch = new System.Diagnostics.TraceSwitch(switchName, string.Empty);
     if (switchName.Length == 0)
         traceSwitch.Level = System.Diagnostics.TraceLevel.Info;
     this.eventSource = eventSource;
 }
示例#17
0
 public static void TraceError(TraceSwitch traceSwitch, Exception exception)
 {
     ValidateArgumentIsNull(traceSwitch);
     ValidateArgumentIsNull(exception);
     if (traceSwitch.TraceError)
     {
         Trace.TraceError(exception.ToString());
     }
 }
示例#18
0
        static LogService()
        {
            TraceSwitch = new TraceSwitch(category, "Trace switch for demacia tool")
            {
                Level = TraceLevel.Verbose
            };

            Log.Logged += ((o, e) => LogService.Logged(o, e));
        }
示例#19
0
 /// <summary>
 /// Creates a new instance of the <see cref="StreamParser"/> class
 /// </summary>
 /// <param name="session">A <see cref="TcpIpSession"/></param>
 /// <param name="responseQueue">A <see cref="ResponseQueue"/> instance to which <see cref="ResponsePDU"/> pdu's are forwarded</param>
 /// <param name="requestProcessor">A callback delegate for processing <see cref="RequestPDU"/> pdu's</param>
 public StreamParser(TcpIpSession session,  ResponseHandler responseQueue,PduProcessorCallback requestProcessor)
 {
     if (session == null) { throw new ArgumentNullException("session"); }
     if (requestProcessor == null) { throw new ArgumentNullException("requestProcessor"); }
     if (responseQueue == null) { throw new ArgumentNullException("responseQueue"); }
     vTcpIpSession = session;
     vProcessorCallback = requestProcessor;
     vResponseHandler = responseQueue;
     //--Create and initialize a trace switch
     vTraceSwitch = new TraceSwitch("StreamParserSwitch", "Stream perser switch");
 }
示例#20
0
文件: licX.cs 项目: mykwillis/licX
 public LicXLicenseProvider()
 {
     traceSwitch = new TraceSwitch( "licX", "Trace switches for licX licensing." );
     if ( traceSwitch.TraceVerbose )
     {
         Trace.WriteLine( "----- licX Assembly Details -----" );
         Trace.WriteLine( "Assembly:               " + Assembly.GetExecutingAssembly() );
         Trace.WriteLine( "License Component Type: " + typeof(LicXLicenseComponent).FullName );
         Trace.WriteLine( "License Component Guid: " + typeof(LicXLicenseComponent).GUID );
         Trace.WriteLine( "-----  end Assembly Details -----" );
     }
 }
示例#21
0
      public CsTrace(string traceSwitchName) {
         _traceApplication = new TraceSwitch(traceSwitchName, "Trace switch for csUnit.");
         _traceApplication.Level = ( new CsTraceSettings() ).TraceLevelForSwitch(traceSwitchName);

         if( _traceApplication.Level != TraceLevel.Off ) {
            string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string targetFile = Path.Combine(myDocuments, traceSwitchName + ".log.txt");
            FileStream myTraceLog = new FileStream(targetFile, FileMode.OpenOrCreate);
            TextWriterTraceListener myListener = new TextWriterTraceListener(myTraceLog);
            Trace.Listeners.Add(myListener);
            Trace.AutoFlush = true;
         }
      }
示例#22
0
 static Config()
 {
     ServerConnectionString = ConfigurationManager.ConnectionStrings["TZeroHost.Properties.Settings.ConfigConn"];
     string aux = ConfigurationManager.AppSettings["TerminalZeroClient.Properties.Settings.TerminalCode"];
     int auxInt;
     int.TryParse(aux, out auxInt);
     TerminalCode = auxInt;
     TerminalName = System.Environment.MachineName;
     IsOnServer = ServerConnectionString != null;
     ClientConnectionString = ConfigurationManager.ConnectionStrings["TerminalZeroClient.Properties.Settings.ConfigConn"];
     UsersConnectionString = ConfigurationManager.ConnectionStrings["TZeroHost.Properties.Settings.UsersConn"];
     LogLevel = new TraceSwitch("ZeroLogLevelSwitch", "Zero Log Level Switch", "Error");
 }
示例#23
0
 private static void LoadTraceLevelFromConfig()
 {
     _configuration =
         (SimpleDataConfigurationSection) ConfigurationManager.GetSection("simpleData/simpleDataConfiguration");
     if (_configuration != null)
     {
         Trace.TraceWarning("SimpleDataConfiguration section is obsolete; use system.diagnostics switches instead.");
         TraceLevel = _configuration.TraceLevel;
     }
     else
     {
         var traceSwitch = new TraceSwitch("Simple.Data", "", TraceLevel.Info.ToString());
         TraceLevel = traceSwitch.Level;
     }
 }
示例#24
0
 private nHydrateLog(string exeName)
 {
     _exeName = exeName;
     _currentSwitch = new TraceSwitch("nHydrate", "nHydrate trace switch for " + exeName);
     try
     {
         SetDefaults();
         //InitializeConfigFile();
         //mAppFileWatcher_Changed(this, new FileSystemEventArgs(WatcherChangeTypes.Changed, _appConfigFile.DirectoryName, _appConfigFile.Name));
     }
     catch (Exception ex)
     {
         LogLogFailure(ex.ToString());
     }
 }
示例#25
0
 public static void TraceVerbose(TraceSwitch traceSwitch, string format, params object[] args)
 {
     ValidateArgumentIsNull(traceSwitch);
     ValidateArgumentIsNull(args);
     if (traceSwitch.TraceVerbose)
     {
         if (args != null && args.Length > 0)
         {
             Trace.TraceInformation(format, args);
         }
         else
         {
             Trace.TraceInformation(format);
         }
     }
 }
示例#26
0
文件: Logger.cs 项目: usbr/Pisces
 /// <summary>
 /// Begin Tracing to log file based on application name.
 /// </summary>
 public static void InitTracing()
 {
     if (_traceSwitch == null)
     {
         _traceSwitch = new TraceSwitch("LoggingLevel", "Controls level of Trace logging output");
         if (_traceSwitch.Level != TraceLevel.Off)
         { // if any tracing.. save to log.
             //string logName = Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".log";
             logName = Path.Combine(FileUtility.GetLocalApplicationPath(), Path.GetFileNameWithoutExtension(Application.ExecutablePath));
             logName = logName + ".log";
             FileStream fs = new FileStream(logName, FileMode.Append);
             TextWriterTraceListener listener = new TextWriterTraceListener(fs);
             Trace.Listeners.Add(listener);
         }
         Trace.AutoFlush = true;
     }
 }
示例#27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Log4netTraceListener"/> class.
        /// </summary>
        public Log4netTraceListener()
        {
            this._generalTraceSwitch = new System.Diagnostics.TraceSwitch("TraceLevelSwitch", "Entire application");

            this._loggerName = (System.Configuration.ConfigurationManager.AppSettings["log4netLoggerName"] != null)?System.Configuration.ConfigurationManager.AppSettings["log4netLoggerName"].ToString():string.Empty;
            // Set default values

            this.Name = "Log4net Trace Listener";

            // Create additional trace sources list
            TraceSourceCollection = new List <TraceSource>();

            // Add additional trace sources - .NET framework
            //..
            // Subscribe to all trace sources
            foreach (TraceSource traceSource in TraceSourceCollection)
            {
                traceSource.Listeners.Add(this);
            }
        }
示例#28
0
    public static int Main()
    {
        System.Diagnostics.TraceSwitch MySwitch = new System.Diagnostics.TraceSwitch("MySwitch", null);
        MySwitch.Level = System.Diagnostics.TraceLevel.Verbose;

        Console.WriteLine("WMI COM+ Test Application");


        //Create a WmiPath object
        WmiPath Path = new WmiPath("root\\cimv2");

        Console.WriteLine("String in WmiPath object is : {0}", Path.PathString);

        //Make a connection to this path
        WmiCollection Session = WmiCollection.Connect(Path);

        //Get a class from this connection
        WmiObject ServiceClass = Session.Get(new WmiPath("Win32_LogicalDisk"));

        //WmiObject ServiceClass = Session.Get("Win32_LogicalDisk");
        //Display the class name (__CLASS property of the class)
        Console.WriteLine("The name of this class is : {0}", ServiceClass["__CLASS"]);

        //Enumerate instances
        WmiCollection Instances = Session.Open(new WmiPath("Win32_LogicalDisk"));

        foreach (WmiObject obj in Instances)
        {
            Console.WriteLine("The key of this instance is : {0}", obj["Name"]);
        }

        //Query
        WmiCollection QueryRes = Session.Query(new WmiQuery("select * from Win32_Service"));

        foreach (WmiObject Service in QueryRes)
        {
            Console.WriteLine("{0}", Service["Name"]);
        }

        return(0);
    }
示例#29
0
 /// <summary>
 /// 根据跟踪开关和消息级别决定是否向监听器写入消息。
 /// </summary>
 /// <param name="ts">跟踪开关</param>
 /// <param name="level">消息级别</param>
 /// <param name="message">消息</param>
 public static void Trace(TraceSwitch ts, TraceLevel level, string message)
 {
     switch (level)
     {
         case TraceLevel.Error:
             TraceError(ts, message);
             break;
         case TraceLevel.Info:
             TraceInformation(ts, message);
             break;
         case TraceLevel.Off:
             break;
         case TraceLevel.Verbose:
             TraceLine(ts, message);
             break;
         case TraceLevel.Warning:
             TraceWarning(ts, message);
             break;
         default:
             break;
     }
 }
示例#30
0
        /// <summary>
        /// 构造函数.
        /// </summary>
        public TestTraceLog()
        {

            // BooleanSwitch 类型的开关, 只有 一个 Enabled 的 开关定义.
            // 构造 跟踪开关.
            dataSwitch = new BooleanSwitch("DataMessagesSwitch", "开关定义在配置文件中...");

            Console.WriteLine("当前 BooleanSwitch 开关配置:");
            Console.WriteLine("  Enabled: {0}", dataSwitch.Enabled);
            Console.WriteLine();


            // TraceSwitch 类型的开关, 有 Error、Warning、Info、Verbose 四个层次的 开关定义.
            // 构造 跟踪开关.
            appSwitch = new TraceSwitch("TraceLevelSwitch", "开关定义在配置文件中...");

            Console.WriteLine("当前 TraceSwitch 开关配置:");
            Console.WriteLine("  TraceError:{0}", appSwitch.TraceError);
            Console.WriteLine("  TraceWarning:{0}", appSwitch.TraceWarning);
            Console.WriteLine("  TraceInfo:{0}", appSwitch.TraceInfo);
            Console.WriteLine("  TraceVerbose:{0}", appSwitch.TraceVerbose);

        }
示例#31
0
        // Define a simple method to write details about the current executing
        // environment to the trace listener collection.
        public static void WriteEnvironmentInfoToTrace()
        {
            TraceSwitch ts = new TraceSwitch("configConsoleListener", "switch");
            string methodName = "WriteEnvironmentInfoToTrace";

            Trace.Indent();
            Trace.WriteLine(DateTime.Now.ToString() + " - Start of " + methodName);
            Trace.Indent();

            // Write details on the executing environment to the trace output.
            Trace.WriteLine("Operating system: " + System.Environment.OSVersion.ToString());
            Trace.WriteLine("Computer name: " + System.Environment.MachineName);
            Trace.WriteLine("User name: " + System.Environment.UserName);
            Trace.WriteLine("CLR runtime version: " + System.Environment.Version.ToString());
            Trace.WriteLine("Command line: " + System.Environment.CommandLine);

            // Enumerate the trace listener collection and
            // display details about each configured trace listener.
            Trace.WriteLine("Number of configured trace listeners = " + Trace.Listeners.Count.ToString());
            #if DEBUG
            foreach (TraceListener tl in Trace.Listeners)
            {
                Trace.WriteLine("Trace listener name = " + tl.Name);
                Trace.WriteLine("               type = " + tl.GetType().ToString());
            }
            #endif

            Trace.Unindent();
            Trace.WriteLine(DateTime.Now.ToString() + " - End of " + methodName);
            Trace.Unindent();
            //Trace.Flush();
            //Trace.WriteLineIf(
            Trace.WriteLineIf(ts.TraceError, "This is a error.");
            Trace.WriteLineIf(ts.TraceWarning, "This is a warning.");
            Trace.Close();
        }
示例#32
0
        static void Main(string[] args)
        {
            // Set global exception handler
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // Enable Tracing
            TRACE_SWITCH = new TraceSwitch("TraceSwitch", "Default trace switch", "3");

            // Get SQL Server configs
            string MSSQLConnectionString = ConfigurationManager.ConnectionStrings["MSSQLConnectionString"].ConnectionString;
            int SQLBatchSize = int.Parse(ConfigurationManager.AppSettings["SQLBatchSize"]);
            int SQLThreads = int.Parse(ConfigurationManager.AppSettings["SQLThreads"]);

            // Configure SQL Server spatial types
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            // Configure OGR
            GdalConfiguration.ConfigureOgr();
            Gdal.SetConfigOption("OGR_INTERLEAVED_READING", "YES");
            Gdal.SetConfigOption("OSM_COMPRESS_NODES", "YES");
            Gdal.SetConfigOption("CPL_TMPDIR", ConfigurationManager.AppSettings["OSMTmpPath"]);
            Gdal.SetConfigOption("OSM_MAX_TMPFILE_SIZE", ConfigurationManager.AppSettings["OSMTmpFileSize"]);
            Gdal.SetConfigOption("OSM_CONFIG_FILE", ConfigurationManager.AppSettings["OSMConfigFile"]);
            DataSource OGRDataSource = Ogr.Open(ConfigurationManager.AppSettings["OSMFile"], 0);

            // Drop SQL tables
            //DropTables(OGRDataSource, MSSQLConnectionString);

            // Create SQL tables and return ADO.NET DataSet of with DataTables
            // DataTables will be used buffer records before SQL bulk insert
            DataSet OSMDataSet = CreateTables(OGRDataSource, MSSQLConnectionString);

            // Start Timer
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            // Do work son!
            log(TraceLevel.Info, "Begin Processing...");
            DoWork(OGRDataSource, OSMDataSet, MSSQLConnectionString, SQLThreads, SQLBatchSize);

            // Create Indexes
            CreateIndexes(OGRDataSource, MSSQLConnectionString);

            // Stop Timer
            stopwatch.Stop();
            log(TraceLevel.Info, string.Format("Time elapsed: {0}", stopwatch.Elapsed));
        }
示例#33
0
 public string getTraceLevel(string swtchName)
 {
     System.Diagnostics.TraceSwitch swtch = new System.Diagnostics.TraceSwitch(swtchName, "asfsjkadhf");
     return(swtch.Level.ToString());
 }
示例#34
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="description"></param>
 public Log(string name, string description)
 {
     _traceSwitch = new System.Diagnostics.TraceSwitch(name, description);
 }