internal static void Enter(TraceSource source, string method) { if(source.Switch.ShouldTrace(TraceEventType.Verbose)) { source.TraceEvent(TraceEventType.Verbose, 0, "Entering --> " + method); } }
internal static void Associate(TraceSource traceSource, object objA, object objB) { if (ValidateSettings(traceSource, TraceEventType.Information)) { PrintLine(traceSource, TraceEventType.Information, 0, "Associating " + (GetObjectName(objA) + "#" + ValidationHelper.HashString(objA)) + " with " + (GetObjectName(objB) + "#" + ValidationHelper.HashString(objB))); } }
public void CanDisposeRepeatedly() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); using (var context = new LogicalOperationScope(traceSource, traceSource.Name)) context.Dispose(); }
internal static void Leave(TraceSource source, string message) { if (source.Switch.ShouldTrace(TraceEventType.Verbose)) { source.TraceEvent(TraceEventType.Verbose, 0, "Leaving <-- " + message); } }
public TraceListenerEx(TraceSource source) { if (source == null) throw new ArgumentNullException("source"); _source = source; }
public void ReturnName() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); using (var context = new LogicalOperationScope(traceSource, traceSource.Name)) Assert.Equal(traceSource.Name, context.ToString()); }
public void SetSourceSwitchTest() { var trace = new TraceSource("TestTraceSource"); var @switch = new SourceSwitch("TestTraceSwitch"); trace.Switch = @switch; Assert.Equal(@switch, trace.Switch); }
public Task Invoke(IDictionary<string, object> env) { // The TraceSource is assumed to be the same across all requests. traceSource = traceSource ?? new Request(env).Get<TraceSource>("host.TraceSource"); if (traceSource == null) { return nextApp(env); } try { TraceCall(env); return nextApp(env).Then(() => { TraceResult(env); }) .Catch(errorInfo => { TraceException(errorInfo.Exception, "asynchronously"); return errorInfo.Throw(); }); } catch (Exception ex) { TraceException(ex, "synchronously"); throw; } }
public void NewLogicalOperationPushedOnToStack() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); using (new LogicalOperationScope(traceSource, traceSource.Name)) Assert.Equal("NewLogicalOperationPushedOnToStack", Trace.CorrelationManager.LogicalOperationStack.Peek()); }
public async Task TestTcpTraceListener() { var listener = new TcpListener(IPAddress.Loopback, 0); listener.Start(); int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port; var traceSource = new TraceSource("UnitTestLogger"); traceSource.Listeners.Remove("Default"); traceSource.Switch.Level = SourceLevels.All; traceSource.Listeners.Add(new TcpTraceListener( IPAddress.Loopback, port, new ExponentialBackoffTcpReconnectionPolicy())); var listenerClient = await listener.AcceptTcpClientAsync(); traceSource.TraceEvent(TraceEventType.Information, 100, "Boris"); var receiverReader = new StreamReader(listenerClient.GetStream()); var line = await receiverReader.ReadLineAsync(); Assert.True(line.EndsWith("UnitTestLogger Information: 100 : Boris")); listenerClient.Close(); listener.Stop(); traceSource.Close(); }
public void EmailFloodManyThreadsMax100() { TraceSource source = new TraceSource("emailFlood2Source"); Action d = () => { try { var guid = Guid.NewGuid(); source.TraceEvent(TraceEventType.Warning, 0, "Message 1 - {0}", guid); source.TraceEvent(TraceEventType.Error, 0, "Message 2 - {0}", guid); } catch (Exception ex) { Debug.WriteLine(string.Format("Action exception: {0}", ex)); } }; for (int i = 0; i < 200; i++) { d.BeginInvoke(null, null); } // Need to wait, otherwise messages haven't been sent and Assert throws exception System.Threading.Thread.Sleep(3000); AssertMessagesSent(100, "Should be limited by max traces of 100."); }
public override void Run() { try { var m = Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run"); var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace"); traceSource.TraceEvent(TraceEventType.Information, 0, m); string cloudContext; if (RoleEnvironment.IsAvailable) { cloudContext = String.Format("{0}|{1}", RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Id); } else { cloudContext = Guid.NewGuid().ToString(); } var jobScheduler = new JobScheduler(cloudContext, traceSource, () => AzureConfiguration.Instance.AzureStorageAccount, new Settings()); traceSource.TraceEvent(TraceEventType.Information, 0, Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run", "Starting Paralel.Invoke", cloudContext)); Parallel.Invoke( jobScheduler.JobsManagerProcess, jobScheduler.SchedulerProcess); } catch (Exception ex) { var m = Helper.FormatException(ex, "WorkerRole", "Run"); var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace"); traceSource.TraceEvent(TraceEventType.Error, 0, m); } }
static void Main(string[] args) { EnableSelfSignedCertificates(); Uri uri = new Uri("https://localhost:8088"); string token = "BEC47D17-AC4A-49ED-834B-969745D24550"; var trace = new TraceSource("conf-demo"); trace.Switch.Level = SourceLevels.All; var listener = new HttpEventCollectorTraceListener(uri, token); trace.Listeners.Add(listener); HashSet<string> files = new HashSet<string>(); while (true) { string[] currentFiles = Directory.GetFiles(args[0]); foreach (string s in currentFiles) { if (!files.Contains(s)) { files.Add(s); string ascii = ToAscii(s.Substring(s.LastIndexOf('\\') + 1), new Bitmap(s, true)); trace.TraceInformation(ascii); trace.Flush(); } } Thread.Sleep(200); } }
public void ShouldLogNetworkCommunication() { // Setup source and listener string initializationString = @"name = XmlLogger; logrootpath = c:\logs\; staticpattern = lognc_; maxSizeBytes = 200000;"; XmlWriterRollingTraceListener traceListener = new XmlWriterRollingTraceListener(initializationString); TraceSource log = new TraceSource("Test", SourceLevels.All); log.Listeners.Clear(); log.Listeners.Add(traceListener); // Start Activity #1 Guid activity1Guid = Guid.NewGuid(); Trace.CorrelationManager.ActivityId = activity1Guid; log.TraceEvent(TraceEventType.Start, 2, "Activity #1"); // log information inside Activity #1 log.TraceInformation("Going to execute HttpWebRequest from Activity #1"); HttpWebRequest request = HttpWebRequest.Create("http://www.google.com/") as HttpWebRequest; WebResponse response = request.GetResponse(); using (StreamReader s = new StreamReader(response.GetResponseStream())) { string value = s.ReadToEnd(); } // Complete Activity #1 log.TraceEvent(TraceEventType.Stop, 8, "Completing Activity #1"); }
public void ActivityIdChangedIfNewGuidSpecified() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); var activityId = Guid.NewGuid(); using (new ActivityScope(traceSource, activityId)) Assert.Equal(activityId, Trace.CorrelationManager.ActivityId); }
protected ConnectionBase(TraceSource traceSource) { this.id = Interlocked.Increment(ref connectionIdCount); Interlocked.CompareExchange(ref connectionIdCount, 0, int.MaxValue); this.traceSource = traceSource; }
private static void TraceInternal(TraceSource traceSource, int eventId, TraceLevel traceLevel, string message) { if (traceSource == null) return; var traceEventType = ConvertTraceLevelToTraceEventType(traceLevel); traceSource.TraceEvent(traceEventType, eventId, message); }
internal static void Dump(TraceSource traceSource, object obj, string method, byte[] buffer, int offset, int length) { if (ValidateSettings(traceSource, TraceEventType.Verbose)) { if (buffer == null) { PrintLine(traceSource, TraceEventType.Verbose, 0, "(null)"); } else if (offset > buffer.Length) { PrintLine(traceSource, TraceEventType.Verbose, 0, "(offset out of range)"); } else { PrintLine(traceSource, TraceEventType.Verbose, 0, "Data from " + GetObjectName(obj) + "#" + ValidationHelper.HashString(obj) + "::" + method); int maxDumpSizeSetting = GetMaxDumpSizeSetting(traceSource); if (length > maxDumpSizeSetting) { PrintLine(traceSource, TraceEventType.Verbose, 0, "(printing " + maxDumpSizeSetting.ToString(NumberFormatInfo.InvariantInfo) + " out of " + length.ToString(NumberFormatInfo.InvariantInfo) + ")"); length = maxDumpSizeSetting; } if ((length < 0) || (length > (buffer.Length - offset))) { length = buffer.Length - offset; } if (GetUseProtocolTextSetting(traceSource)) { string msg = "<<" + WebHeaderCollection.HeaderEncoding.GetString(buffer, offset, length) + ">>"; PrintLine(traceSource, TraceEventType.Verbose, 0, msg); } else { do { int num2 = Math.Min(length, 0x10); string str2 = string.Format(CultureInfo.CurrentCulture, "{0:X8} : ", new object[] { offset }); for (int i = 0; i < num2; i++) { str2 = str2 + string.Format(CultureInfo.CurrentCulture, "{0:X2}", new object[] { buffer[offset + i] }) + ((i == 7) ? '-' : ' '); } for (int j = num2; j < 0x10; j++) { str2 = str2 + " "; } str2 = str2 + ": "; for (int k = 0; k < num2; k++) { str2 = str2 + (((buffer[offset + k] < 0x20) || (buffer[offset + k] > 0x7e)) ? '.' : ((char) buffer[offset + k])); } PrintLine(traceSource, TraceEventType.Verbose, 0, str2); offset += num2; length -= num2; } while (length > 0); } } } }
public void DoNotTraceStartEventWhenTracingDisabled() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); var listener = new FakeTraceListener(); traceSource.Listeners.Add(listener); using (new LogicalOperationScope(traceSource, traceSource.Name, traceEnabled: false)) Assert.Equal(0, listener.Messages.Count(m => m.Trim() == $"Logical operation {traceSource.Name} started")); }
internal static void Dump(TraceSource traceSource, object obj, string method, IntPtr bufferPtr, int length) { if ((ValidateSettings(traceSource, TraceEventType.Verbose) && (bufferPtr != IntPtr.Zero)) && (length >= 0)) { byte[] destination = new byte[length]; Marshal.Copy(bufferPtr, destination, 0, length); Dump(traceSource, obj, method, destination, 0, length); } }
public static void NLogTraceHandler(TraceSource source, TraceLevel traceLevel, Exception exception, string message, params object[] formatArgs) { var logger = NLog.LogManager.GetLogger(source.Name); switch (traceLevel) { case TraceLevel.Debug: if (exception == null) { logger.Debug(message, formatArgs); } else { logger.Debug(exception, message, formatArgs); } break; case TraceLevel.Info: if (exception == null) { logger.Info(message, formatArgs); } else { logger.Info(exception, message, formatArgs); } break; case TraceLevel.Warn: if (exception == null) { logger.Warn(message, formatArgs); } else { logger.Warn(exception, message, formatArgs); } break; case TraceLevel.Error: if (exception == null) { logger.Error(message, formatArgs); } else { logger.Error(exception, message, formatArgs); } break; case TraceLevel.Fatal: if (exception == null) { logger.Fatal(message, formatArgs); } else { logger.Fatal(exception, message, formatArgs); } break; } }
/// <summary> /// /// </summary> static SocketClient() { #if !NETFX_CORE TraceSource = new TraceSource("HigLabo.Net.SocketClient"); #endif #if !NETFX_CORE && !DEBUG TraceSource.Listeners.Clear(); #endif }
// ���O����� public void Close() { if (IsInit()) { m_logSrc.Listeners.Clear(); m_logSrc.Close(); m_logSrc = null; } }
static void Main(string[] args) { IPEndPoint serviceEndPoint = new IPEndPoint(IPAddress.Loopback, 25673); ChatService service = new ChatService(serviceEndPoint); ChatClient client = new ChatClient(serviceEndPoint); var trace = new TraceSource("Custom", SourceLevels.All); var disposable = service.Start(trace); client.Connect(); }
public void PruneTest() { var strongTrace = new TraceSource("TestTraceSource"); var traceRef = new WeakReference(new TraceSource("TestTraceSource")); Assert.True(traceRef.IsAlive); GC.Collect(2); Trace.Refresh(); Assert.False(traceRef.IsAlive); GC.Collect(2); Trace.Refresh(); }
public async Task ConnectAsync(string connectionString, TraceSource trace) { _connection = await ConnectToRedis(connectionString); _connection.ConnectionFailed += OnConnectionFailed; _connection.ConnectionRestored += OnConnectionRestored; _connection.ErrorMessage += OnError; _trace = trace; _redisSubscriber = _connection.GetSubscriber(); }
public void TraceInformationTest() { var trace = new TraceSource("TestTraceSource", SourceLevels.All); var listener = new TestTraceListener(); trace.Listeners.Add(listener); trace.TraceInformation("message"); Assert.Equal(0, listener.GetCallCount(Method.TraceData)); Assert.Equal(0, listener.GetCallCount(Method.Write)); Assert.Equal(1, listener.GetCallCount(Method.TraceEvent)); trace.TraceInformation("format", "arg1", "arg2"); Assert.Equal(2, listener.GetCallCount(Method.TraceEvent)); }
public void TraceSource_Accepts_Custom_TraceSource() { // Arrange SystemDiagnosticsTraceWriter writer = new SystemDiagnosticsTraceWriter(); TraceSource traceSource = new TraceSource("CustomTraceSource"); // Act writer.TraceSource = traceSource; // Assert Assert.Equal(traceSource, writer.TraceSource); }
public void EmailFilterSendFiltered() { TraceSource source = new TraceSource("emailFilterSource"); source.TraceEvent(TraceEventType.Error, 0, "Include Error."); source.TraceInformation("Include Info."); source.TraceEvent(TraceEventType.Verbose, 0, "Default filter does not include Verbose."); System.Threading.Thread.Sleep(2000);//need to wait, otherwise the test host is terminated resulting in thread abort. AssertMessagesSent(2); }
public void DoNotTraceTransferIfTracingDisabled() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); var listener = new FakeTraceListener(); var activityId = Guid.NewGuid(); traceSource.Listeners.Add(listener); Trace.CorrelationManager.ActivityId = activityId; using (new ActivityScope(traceSource, Guid.NewGuid(), traceEnabled: false)) Assert.Equal(0, listener.Messages.Count(m => m == String.Format("Transfer from {0} to {1}, relatedActivityId={1}", activityId, activityId))); }
public static void TraceWarning(this TraceSource traceSource, string message) { traceSource.TraceEvent(TraceEventType.Warning, (int)TraceEventType.Warning, message); }
public TraceCorrelation(TraceSource source, string activityName) : this(Guid.NewGuid(), source, activityName) { }
public TraceCorrelation(Guid activity, TraceSource source, string activityName) { _Source = source; _ActivityName = activityName; this.activity = activity; }
static Trace() { _source = new TraceSource("dk.nita.saml20"); }
static TraceSourceLogger() { _source = new TraceSource("Thinktecture.IdentityServer"); }
public static TraceCallScope TraceMethod( this TraceSource source, [CallerMemberName] string method = null) { return(new TraceCallScope(source, method)); }
public TraceLogger(string logName) { this._logName = "[" + (logName ?? string.Empty) + "] "; this.traceSource = new TraceSource("TraceLogger", SourceLevels.All); }
static Storage() { Trace = new TraceSource("Storage", SourceLevels.All); }
public TraceSourceLogger(TraceSource traceSource) { this.traceSource = traceSource; }
/// <summary> /// Writes an error message to the specified trace. /// </summary> /// <param name="trace">The trace.</param> /// <param name="source">Subsystem name to help with log categorizing, filtering</param> /// <param name="id">The event identifier.</param> /// <param name="messageFormat">Format of the string field</param> /// <param name="args">String format arguments</param> public static void Maintenance(this TraceSource trace, string source, int id, string messageFormat, params object[] args) { trace.TraceEvent(TraceEventType.Critical, id, FormatMessage2(source, messageFormat, args)); }
/// <summary> /// Writes an error message to the specified trace. /// </summary> /// <param name="trace">The trace.</param> /// <param name="source">Subsystem name to help with log categorizing, filtering</param> /// <param name="id">The event identifier.</param> /// <param name="ex">The exception to log</param> public static void Error(this TraceSource trace, string source, int id, Exception ex) { //trace.TraceData(TraceEventType.Error, id, FormatMessage(source, "{0}", ex)); trace.TraceEvent(TraceEventType.Error, id, FormatMessage(source, "{0}", ex)); }
/// <summary> /// Writes an error message to the specified trace. /// </summary> /// <param name="trace">The trace.</param> /// <param name="source">Subsystem name to help with log categorizing, filtering</param> /// <param name="id">The event identifier.</param> /// <param name="messageFormat">Format of the string field</param> /// <param name="args">String format arguments</param> public static void Error(this TraceSource trace, string source, int id, string messageFormat, params object[] args) { trace.TraceEvent(TraceEventType.Error, id, FormatMessage(source, messageFormat, args)); }
public Log(TraceSource source, string prefix) { this.source = source; this.prefix = prefix; }
/// <summary> /// Writes an error message to the specified trace. /// </summary> /// <param name="trace">The trace.</param> /// <param name="source">Subsystem name to help with log categorizing, filtering</param> /// <param name="messageFormat">Format of the string field</param> /// <param name="args">String format arguments</param> public static void Error(this TraceSource trace, string source, string messageFormat, params object[] args) { trace.TraceEvent(TraceEventType.Warning, Thread.CurrentThread.ManagedThreadId, FormatMessage(source, messageFormat, args)); }
static TraceSourceLogger() { _source = new TraceSource("IdentityManager"); }
public static void TraceVerbose(this TraceSource traceSource, string message) { traceSource.TraceEvent(TraceEventType.Verbose, (int)TraceEventType.Verbose, message); }
public SystemTraceSink(TraceSource traceSource) { _traceSource = traceSource; }
public async Task InitializeAsync() { Tuple <Nerdbank.FullDuplexStream, Nerdbank.FullDuplexStream> streams = Nerdbank.FullDuplexStream.CreateStreams(); TraceSource mxServerTraceSource = new TraceSource("MX Server", SourceLevels.Information); TraceSource mxClientTraceSource = new TraceSource("MX Client", SourceLevels.Information); mxServerTraceSource.Listeners.Add(new XunitTraceListener(this.Logger)); mxClientTraceSource.Listeners.Add(new XunitTraceListener(this.Logger)); MultiplexingStream[] mxStreams = await Task.WhenAll( MultiplexingStream.CreateAsync( streams.Item1, new MultiplexingStream.Options { TraceSource = mxServerTraceSource, DefaultChannelTraceSourceFactory = (id, name) => new TraceSource("MX Server channel " + id, SourceLevels.Verbose) { Listeners = { new XunitTraceListener(this.Logger) } }, }, this.TimeoutToken), MultiplexingStream.CreateAsync( streams.Item2, new MultiplexingStream.Options { TraceSource = mxClientTraceSource, DefaultChannelTraceSourceFactory = (id, name) => new TraceSource("MX Client channel " + id, SourceLevels.Verbose) { Listeners = { new XunitTraceListener(this.Logger) } }, }, this.TimeoutToken)); this.serverMx = mxStreams[0]; this.clientMx = mxStreams[1]; MultiplexingStream.Channel[] rpcStreams = await Task.WhenAll( this.serverMx.AcceptChannelAsync(string.Empty, this.TimeoutToken), this.clientMx.OfferChannelAsync(string.Empty, this.TimeoutToken)); MultiplexingStream.Channel rpcServerStream = rpcStreams[0]; MultiplexingStream.Channel rpcClientStream = rpcStreams[1]; var serverFormatter = new JsonMessageFormatter { MultiplexingStream = this.serverMx }; var clientFormatter = new JsonMessageFormatter { MultiplexingStream = this.clientMx }; var serverHandler = new HeaderDelimitedMessageHandler(rpcServerStream, serverFormatter); var clientHandler = new HeaderDelimitedMessageHandler(rpcClientStream, clientFormatter); this.serverRpc = new JsonRpc(serverHandler, this.server); this.clientRpc = new JsonRpc(clientHandler); this.serverRpc.TraceSource = new TraceSource("Server", SourceLevels.Information); this.clientRpc.TraceSource = new TraceSource("Client", SourceLevels.Information); this.serverRpc.TraceSource.Listeners.Add(new XunitTraceListener(this.Logger)); this.clientRpc.TraceSource.Listeners.Add(new XunitTraceListener(this.Logger)); this.serverRpc.StartListening(); this.clientRpc.StartListening(); }
/// <summary> /// Constructor. Sets the ActivityId for the life of the object, logging events but without specific event IDs. /// </summary> public ActivityScope(TraceSource source) : this(new TraceSourceWrapper(source), 0, 0, 0, 0, null, null, null, null, null) { }
public static bool ShouldTrace(this TraceSource source, MessageId id) { Contract.Assert(source != null); return(source.Switch.ShouldTrace(_typeTable[id])); }
static Log() { TraceSource = new TraceSource("EarnTraceSource", SourceLevels.All); }
public ActivityScope(TraceSource source, int transferInId, int startId, int transferOutId, int stopId) : this(new TraceSourceWrapper(source), transferInId, startId, transferOutId, stopId, null, null, null, null, null) { }
public CalculatorService() { ts = new TraceSource("ServerCalculatorTraceSource"); }
public ActivityScope(TraceSource source, int transferInId, int startId, int transferOutId, int stopId, string transferInMessage, string startMessage, string transferOutMessage, string stopMessage) : this(new TraceSourceWrapper(source), transferInId, startId, transferOutId, stopId, transferInMessage, startMessage, transferOutMessage, stopMessage, null) { }
public static IObservable <T> TraceOnCompleted <T>(this IObservable <T> source, TraceSource trace, Func <string> messageSelector) { Contract.Requires(source != null); Contract.Requires(trace != null); Contract.Requires(messageSelector != null); Contract.Ensures(Contract.Result <IObservable <T> >() != null); return(source.Do(new TraceObserver <T>(trace, _ => null, messageSelector))); }
private static void Main(string[] args) { string dt = $"{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}"; FileSystemHandler fsh = new FileSystemHandler(new FSHandlerOptions("c:\\Temp\\votalot\\dummy" + dt + ".log")); fsh.SetFormatter(new FlimFlamV2Formatter()); Bilge.AddMessageHandler(new ConsoleHandler()); Bilge.AddMessageHandler(new TCPHandler("127.0.0.1", 9060)); Bilge.AddMessageHandler(fsh); Bilge.Alert.Online("TestClient"); #if CORE // Due to the dependency on configurations and the different ways that you can configure a core service this is not // implemented within Bilge even as a default but is documented instead. Bilge.SetConfigurationResolver((s, lvl) => { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", false, true) .Build(); SourceLevels result = lvl; string defaultValue = configuration["logging:loglevel:default"]; string specificForThisInstance = configuration[$"logging:loglevel:{s}"]; if (Enum.TryParse <SourceLevels>(specificForThisInstance, out SourceLevels slSpecific)) { result = slSpecific; } else { if (Enum.TryParse <SourceLevels>(defaultValue, out SourceLevels slDefault)) { result = slDefault; } } return(result); }); #else Bilge.SetConfigurationResolver((instanceName, lvl) => { // Logic -> Try Source Switch, Failing that Trace Switch, failing that SourceSwitch + Switch, Failing that TraceSwitch+Switch. SourceLevels result = lvl; bool tryTraceSwitches = true; try { SourceSwitch ss = new SourceSwitch(instanceName); if (ss.Level == SourceLevels.Off) { ss = new SourceSwitch($"{instanceName}Switch"); if (ss.Level == SourceLevels.Off) { } else { tryTraceSwitches = false; result = ss.Level; } } else { tryTraceSwitches = false; result = ss.Level; } } catch (SystemException) { // This is the higher level exception of a ConfigurationErrorsException but that one requires a separate reference // This occurs when a TraceSwitch has the same name as the source switch with a value that is not supported by source switch e.g. Info } if (tryTraceSwitches) { TraceSwitch ts = new TraceSwitch(instanceName, ""); if (ts.Level == TraceLevel.Off) { ts = new TraceSwitch($"{instanceName}Switch", ""); if (ts.Level != TraceLevel.Off) { result = Bilge.ConvertTraceLevel(ts.Level); } } else { result = Bilge.ConvertTraceLevel(ts.Level); } } return(result); }); #endif Bilge b = new Bilge("PliskyConsoleTestApp"); b.ActiveTraceLevel = SourceLevels.Verbose; b.Verbose.Log("Hello Cruel World"); bool traceSwitchTests = false; bool bulkFileWriteTests = false; bool perfTests = false; bool basicWriteAllTest = true; bool actionTest = true; if (actionTest) { int acCount = 0; b.Action.RegisterHandler((m) => { if (m.Success) { acCount++; } }, "bob"); b.Action.Occured("Event", "Data"); if (acCount == 0) { throw new InvalidOperationException("didnt work"); } } if (basicWriteAllTest) { Bilge.SetConfigurationResolver((instanceName, lvl) => { return(SourceLevels.Verbose); }); ModularWriting mw = new ModularWriting(); mw.DoWrite(); } if (bulkFileWriteTests) { ProductionLoggingTest(b); } b.Flush(); if (perfTests) { PerformanceTest p = new PerformanceTest(); p.AnalysisBatchVsNoBatch(); //p.ExecuteTest(); p.WriteOutput(); Bilge.ForceFlush(); } Console.ReadLine(); return; b.AddHandler(new SimpleTraceFileHandler(@"c:\temp\")); if (traceSwitchTests) { Console.WriteLine("Actual Trace Level : " + b.ActiveTraceLevel.ToString()); try { TraceSource ts = new TraceSource("monkeySwitch", SourceLevels.Off); TraceSwitch tx = new TraceSwitch("monkey2Switch", "test", "Off"); SourceSwitch sw = new SourceSwitch("boner", "off"); Console.WriteLine($"{ts.Switch.Level} >> {tx.Level} >> {sw.Level}"); Console.ReadLine(); } catch (Exception ex) { } } bool doDirectWriting = false; if (args.Length > 0) { if (args[0] == "direct") { doDirectWriting = true; } } if (doDirectWriting) { var dr = new DirectWriting(b); dr.DoDirectWrites(); } ModularWriting mr = new ModularWriting(); mr.DoWrite(); b.Flush(); Console.WriteLine("Readline"); Console.ReadLine(); }
/// <summary> /// Create a new instance of this trace manager /// </summary> public TraceManager() { // Create default source source = new TraceSource("LMS"); }
private Logger() { _traceSource = new TraceSource("Workflow"); }
/// <summary> /// Writes an error message to the specified trace. /// </summary> /// <param name="trace">The trace.</param> /// <param name="source">Subsystem name to help with log categorizing, filtering</param> /// <param name="ex">The exception to log</param> public static void Error(this TraceSource trace, string source, Exception ex) { trace.TraceData(TraceEventType.Error, Thread.CurrentThread.ManagedThreadId, FormatMessage(source, "{0}", ex)); }
/// <summary> /// Initializes a new instance of the <see cref="TypeWrapper"/> class. /// </summary> /// <param name="type"> /// Type to be wrapped. /// </param> public TypeWrapper(TypeDefinition type) { this.m_Type = type; this.m_Module = type.Module; this.m_TraceSource = new TraceSource("TypeWrapper"); }