本文整理汇总了C#中System.Diagnostics.TraceSwitch类的典型用法代码示例。如果您正苦于以下问题:C# TraceSwitch类的具体用法?C# TraceSwitch怎么用?C# TraceSwitch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceSwitch类属于System.Diagnostics命名空间,在下文中一共展示了TraceSwitch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Logger
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
}
示例2: Trace
internal static void Trace(TraceSwitch traceSwitch, string message)
{
if (traceSwitch != null)
{
Debug.WriteLine(traceSwitch.DisplayName + ": " + message);
}
}
示例3: Log
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");
}
示例4: DbConnectionPoolCounters
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);
}
示例5: Main
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");
}
开发者ID:hugonjerome,项目名称:CSharp-5-Developpez-des-applications-Windows-avec-Visual-Studio-2012,代码行数:25,代码来源:Program.cs
示例6: LoggerBase
/// <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;
}
示例7: isLoggable
/// <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;
}
示例8: Log
static Log()
{
TraceSwitch = new TraceSwitch(category, "Trace switch for irelia engine")
{
Level = TraceLevel.Verbose
};
}
示例9: Log
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));
}
}
示例10: decomp
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: StartLogging
/// <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: OutputWindowTraceListener
/// <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;
}
示例13: EventLogger
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());
}
示例14: TraceInformation
public static void TraceInformation(TraceSwitch traceSwitch, string information)
{
ValidateArgumentIsNull(traceSwitch);
if (traceSwitch.TraceInfo)
{
Trace.TraceInformation(information);
}
}
示例15: LogHelp
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");
}