本文整理汇总了C#中System.Diagnostics.TraceSource类的典型用法代码示例。如果您正苦于以下问题:C# TraceSource类的具体用法?C# TraceSource怎么用?C# TraceSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceSource类属于System.Diagnostics命名空间,在下文中一共展示了TraceSource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TraceLogger
public TraceLogger(IConfigurationManager logConfig)
{
ArgumentValidator.ValidateNonNullReference(logConfig,"logConfig","TraceLogger.Ctor()");
this._traceSource = new TraceSource(TraceSourceName) { Switch = new SourceSwitch(TraceSwitchName) };
LogLevel logLevel;
Enum.TryParse(logConfig.SystemConfiguration["LogLevel"], out logLevel);
switch (logLevel)
{
case LogLevel.Off:
this._traceSource.Switch.Level = SourceLevels.Off;
break;
case LogLevel.Critical:
this._traceSource.Switch.Level = SourceLevels.All;
break;
case LogLevel.Error:
this._traceSource.Switch.Level = SourceLevels.Critical | SourceLevels.Error;
break;
case LogLevel.Warning:
this._traceSource.Switch.Level = SourceLevels.Critical | SourceLevels.Error | SourceLevels.Warning;
break;
case LogLevel.Information:
this._traceSource.Switch.Level = SourceLevels.Critical | SourceLevels.Error | SourceLevels.Warning | SourceLevels.Information;
break;
case LogLevel.Verbose:
this._traceSource.Switch.Level = SourceLevels.Critical | SourceLevels.Error | SourceLevels.Warning | SourceLevels.Information | SourceLevels.Verbose;
break;
}
}
开发者ID:rajvarma,项目名称:Sagetest,代码行数:30,代码来源:TraceLogger.cs
示例2: RMQServiceBusInterface
RMQServiceBusInterface( ServiceBusClient dispatcher, TraceSource tracer )
{
if (dispatcher == null)
throw new ArgumentNullException("entity");
Process = dispatcher;
this.Tracer = tracer;
}
开发者ID:rozacki,项目名称:SimpleIPC,代码行数:7,代码来源:RMQServiceBusInterface.cs
示例3: SqlSender
public SqlSender(string connectionString, string tableName, TraceSource traceSource, IDbProviderFactory dbProviderFactory)
{
_connectionString = connectionString;
_insertDml = BuildInsertString(tableName);
_trace = traceSource;
_dbProviderFactory = dbProviderFactory;
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:7,代码来源:SqlSender.cs
示例4: SqlInstaller
public SqlInstaller(string connectionString, string tableNamePrefix, int tableCount, TraceSource traceSource)
{
_connectionString = connectionString;
_messagesTableNamePrefix = tableNamePrefix;
_tableCount = tableCount;
_trace = traceSource;
}
开发者ID:KeithLee208,项目名称:SignalR-Server,代码行数:7,代码来源:SqlInstaller.cs
示例5: submitCodeBehindButton_Click
protected void submitCodeBehindButton_Click(object sender, EventArgs e)
{
System.Diagnostics.TraceSource source =
new System.Diagnostics.TraceSource(sourceTextBox.Text);
source.TraceData(System.Diagnostics.TraceEventType.Error, 100, "Test from the code behind");
}
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:7,代码来源:LoggingPage.aspx.cs
示例6: ObservableDbOperation
public ObservableDbOperation(string connectionString, string commandText, TraceSource traceSource, IDbProviderFactory dbProviderFactory, IDbBehavior dbBehavior)
: base(connectionString, commandText, traceSource, dbProviderFactory)
{
_dbBehavior = dbBehavior ?? this;
InitEvents();
}
开发者ID:kietnha,项目名称:SignalR,代码行数:7,代码来源:ObservableDbOperation.cs
示例7: SimpleEmailer
public SimpleEmailer(string host, int port, string userName, string password, string domain, bool useSsl, string fromAddress, string fromName)
{
string traceName = this.GetType().FullName;
Trace.WriteLine(string.Format("Creating TraceSource {0}. Please register a listener for detailed information.", traceName));
_Trace = new TraceSource(traceName);
_Trace.TraceInformation("Creating SmtpTransport: UserName:{0}, Password: -, Domain:{1}, Host:{2}, Port:{3}, SSL:{4}", userName, domain, host, port, useSsl);
_Client = new SmtpClient(host,port);
_Trace.TraceInformation("Created SMTP Client - {0}:{1}", host, port);
_Client.EnableSsl = useSsl;
_From = new MailAddress(fromAddress, fromName);
_Trace.TraceInformation("From address set to {0} [{1}]", _From.Address, _From.DisplayName);
if (!string.IsNullOrEmpty(userName))
{
_Client.UseDefaultCredentials = false;
_Client.Credentials = new System.Net.NetworkCredential(userName, password, domain);
_Trace.TraceInformation("Created credentials for {0}\\{1}", domain, userName);
}
else
{
_Client.UseDefaultCredentials = true;
_Trace.TraceInformation("Using default credentials");
}
}
开发者ID:mrgcohen,项目名称:CriticalResultsTransporter,代码行数:28,代码来源:SimpleEmailer.cs
示例8: Configure
public static HttpConfiguration Configure(IdentityServerOptions options, ILifetimeScope container)
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.SuppressDefaultHostAuthentication();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger());
config.Services.Replace(typeof(IHttpControllerTypeResolver), new HttpControllerTypeResolver());
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;
if (options.LoggingOptions.EnableWebApiDiagnostics)
{
var liblog = new TraceSource("LibLog");
liblog.Switch.Level = SourceLevels.All;
liblog.Listeners.Add(new LibLogTraceListener());
var diag = config.EnableSystemDiagnosticsTracing();
diag.IsVerbose = options.LoggingOptions.WebApiDiagnosticsIsVerbose;
diag.TraceSource = liblog;
}
ConfigureRoutes(options, config);
return config;
}
开发者ID:0mn1bu5,项目名称:IdentityServer3,代码行数:30,代码来源:WebApiConfig.cs
示例9: TestListeners
public static bool TestListeners(TraceSource source, Type[] types, string[] names, Type[] filters)
{
//This tests all the listeners for a TestSource
TraceListenerCollection collection = source.Listeners;
for (int i = 0; i < types.Length; i++)
{
bool found = false;
for (int j = 0; j < collection.Count; j++)
{
if (collection[j].GetType().Equals(types[i]))
{
found = true;
Assert.True(collection[j].Name == names[i]);
if (filters[i] == null)
Assert.True(collection[j].Filter == null);
else
Assert.True(collection[j].Filter.GetType().Equals(filters[i]));
}
}
Assert.True(found);
}
return true;
}
开发者ID:gitter-badger,项目名称:corefx,代码行数:25,代码来源:CommonUtilities.cs
示例10: MethodWrapper
/// <summary>
/// Initializes a new instance of the <see cref="Process4.Task.Wrappers.MethodWrapper"/> class.
/// </summary>
/// <param name="method">The method to wrap.</param>
public MethodWrapper(MethodDefinition method)
{
this.m_Method = method;
this.m_Type = method.DeclaringType;
this.m_Module = method.Module;
this.m_TraceSource = new TraceSource("MethodWrapper");
}
开发者ID:hach-que,项目名称:Dx,代码行数:11,代码来源:MethodWrapper.cs
示例11: InitializeTraceSource
private TraceSource InitializeTraceSource(string key)
{
var traceSource = new TraceSource(key);
if (key == RootTraceName)
{
if (HasDefaultSwitch(traceSource))
{
traceSource.Switch = _switch;
}
}
else
{
if (HasDefaultListeners(traceSource))
{
TraceSource rootSource = GetOrAddTraceSource(RootTraceName);
traceSource.Listeners.Clear();
traceSource.Listeners.AddRange(rootSource.Listeners);
}
if (HasDefaultSwitch(traceSource))
{
TraceSource rootSource = GetOrAddTraceSource(RootTraceName);
traceSource.Switch = rootSource.Switch;
}
}
return traceSource;
}
开发者ID:tkggand,项目名称:katana,代码行数:27,代码来源:DefaultTraceFactory.cs
示例12: AgentMessageTable
private AgentMessageTable()
{
id = Guid.NewGuid().ToString();
log = new TraceSource(name);
Hashtable t = new Hashtable();
messageTable = Hashtable.Synchronized(t);
}
开发者ID:mil-oss,项目名称:fgsms,代码行数:7,代码来源:AgentMessageTable.cs
示例13: TracerConfig
internal TracerConfig(string cfg)
{
if (string.IsNullOrEmpty(cfg))
{
return;
}
var source = new TraceSource(TraceEnvVarName, SourceLevels.All);
this.myListeners = source.Listeners;
var parser = new TraceCfgParser(cfg);
var newListener = parser.OutDevice;
this.myFilters = parser.Filters;
this.myNotFilters = parser.NotFilters;
if (newListener != null)
{
// when the App.config _Trace source should be used we do not replace
// anything
if (!parser.UseAppConfigListeners)
{
this.myListeners.Clear();
this.myListeners.Add(newListener);
}
}
else
{
this.myListeners = null;
}
}
开发者ID:endjin,项目名称:Endjin.Assembly.ChangeDetection,代码行数:30,代码来源:TracerConfig.cs
示例14: Configure
public static HttpConfiguration Configure(WsFederationPluginOptions options)
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.SuppressDefaultHostAuthentication();
config.MessageHandlers.Insert(0, new KatanaDependencyResolver());
config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger());
config.Services.Replace(typeof(IHttpControllerTypeResolver), new HttpControllerTypeResolver());
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;
if (options.IdentityServerOptions.LoggingOptions.EnableWebApiDiagnostics)
{
var liblog = new TraceSource("LibLog");
liblog.Switch.Level = SourceLevels.All;
liblog.Listeners.Add(new LibLogTraceListener());
var diag = config.EnableSystemDiagnosticsTracing();
diag.IsVerbose = options.IdentityServerOptions.LoggingOptions.WebApiDiagnosticsIsVerbose;
diag.TraceSource = liblog;
}
if (options.IdentityServerOptions.LoggingOptions.EnableHttpLogging)
{
config.MessageHandlers.Add(new RequestResponseLogger());
}
return config;
}
开发者ID:ryanmar,项目名称:IdentityServer3.WsFederation,代码行数:33,代码来源:WebApiConfig.cs
示例15: ServiceContainer
/// <summary>
/// 初始化服务容器
/// </summary>
/// <param name="serviceName"> 服务约定名称 </param>
/// <param name="serviceType"> 服务约定基类或接口类型 </param>
/// <param name="typeComparer"> 比较2个类型服务的优先级 </param>
/// <param name="logger"> 日志记录器 </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="serviceName" /> and <paramref name="serviceType" /> is all
/// <see langword="null" />.
/// </exception>
/// <exception cref="OverflowException"> 匹配插件数量超过字典的最大容量 (<see cref="F:System.Int32.MaxValue" />)。 </exception>
protected ServiceContainer(string serviceName, Type serviceType, IComparer<Type> typeComparer, TraceSource logger = null)
{
TypeComparer = typeComparer;
_logger = logger ?? LogServices.Logger;
_items = new ConcurrentDictionary<Type, ServiceItem>();
_logger?.Write(TraceEventType.Start, $"开始扫描服务插件 serviceName={serviceName},serviceType={serviceType}");
foreach (var p in MEF.PlugIns.GetPlugIns(serviceName, serviceType).OrderByDescending(p => p.Priority))
{
var value = p.GetValue(serviceType);
if (value == null)
{
continue;
}
var type = GetServiceType(p, value);
if (type == null)
{
continue;
}
var item = new ServiceItem(this, type, value, p);
item.MakeSystem(); //默认为系统插件
if (_items.TryAdd(type, item) == false)
{
_logger?.Write(TraceEventType.Verbose, $"服务插件({value.GetType().FullName})因优先级({p.Priority})过低被抛弃");
}
else
{
_logger?.Write(TraceEventType.Verbose, $"服务插件({value.GetType().FullName}),优先级({p.Priority})装载完成");
}
}
_logger?.Write(TraceEventType.Stop, $"服务插件装载完成,有效服务 {Count} 个");
}
开发者ID:blqw,项目名称:blqw.IOC,代码行数:43,代码来源:ServiceContainer.cs
示例16: TraceSources
static TraceSources()
{
TemplateSource = new TraceSource("LostDoc.Core.Template", SourceLevels.All);
AssetResolverSource = new TraceSource("LostDoc.Core.Template.AssetResolver", SourceLevels.All);
GeneratorSource = new TraceSource("LostDoc.Core.DocGenerator", SourceLevels.All);
BundleSource = new TraceSource("LostDoc.Core.Bundle", SourceLevels.All);
}
开发者ID:abclassic,项目名称:LBi.LostDoc,代码行数:7,代码来源:TraceSources.cs
示例17: TraceTransferScope
/// <summary>
/// Constructor used to initialize the class
/// </summary>
/// <param name="traceSource">The source that we are tracing through as part of this scope</param>
/// <param name="activityName">The name of the activity that this scope represents</param>
public TraceTransferScope(TraceSource traceSource, string activityName)
{
if (traceSource == null)
{
throw new ArgumentNullException("traceSource");
}
if (string.IsNullOrEmpty(activityName))
{
throw new ArgumentNullException("activityName");
}
_traceSource = traceSource;
_oldActivityId = Trace.CorrelationManager.ActivityId;
_activityName = activityName;
_newActivityId = Guid.NewGuid();
if (_oldActivityId != Guid.Empty)
{
// transfer to activity
_traceSource.TraceTransfer(0, string.Format(CultureInfo.CurrentCulture, "TRANSFER ==> {0} ===", _activityName), _newActivityId);
}
Trace.CorrelationManager.ActivityId = _newActivityId;
_traceSource.Start(_activityName);
}
开发者ID:vip32,项目名称:eventfeedback,代码行数:32,代码来源:TraceTransferScope.cs
示例18: UsesTraceSource
public void UsesTraceSource()
{
Console.WriteLine("Config:"+ AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
Assert.AreEqual("FromAppConfig", ConfigurationManager.AppSettings["appConfigCheck"]);
// just ensure, that <system.diagnostics> is configured for our test
Trace.Refresh();
TraceSource ts = new TraceSource("TraceLoggerTests", SourceLevels.All);
Assert.AreEqual(1, ts.Listeners.Count);
Assert.AreEqual(typeof(CapturingTraceListener), ts.Listeners[0].GetType());
CapturingTraceListener.Events.Clear();
ts.TraceEvent(TraceEventType.Information, 0, "message");
Assert.AreEqual(TraceEventType.Information, CapturingTraceListener.Events[0].EventType);
Assert.AreEqual("message", CapturingTraceListener.Events[0].FormattedMessage);
// reset events and set loggerFactoryAdapter
CapturingTraceListener.Events.Clear();
NameValueCollection props = new NameValueCollection();
props["useTraceSource"] = "TRUE";
TraceLoggerFactoryAdapter adapter = new TraceLoggerFactoryAdapter(props);
adapter.ShowDateTime = false;
LogManager.Adapter = adapter;
ILog log = LogManager.GetLogger("TraceLoggerTests");
log.WarnFormat("info {0}", "arg");
Assert.AreEqual(TraceEventType.Warning, CapturingTraceListener.Events[0].EventType);
Assert.AreEqual("[WARN] TraceLoggerTests - info arg", CapturingTraceListener.Events[0].FormattedMessage);
}
开发者ID:Rocketmakers,项目名称:common-logging,代码行数:30,代码来源:TraceLoggerTests.cs
示例19: HttpRequestLifeTime
public HttpRequestLifeTime(TransportDisconnectBase transport, TaskQueue writeQueue, TraceSource trace, string connectionId)
{
_transport = transport;
_trace = trace;
_connectionId = connectionId;
_writeQueue = writeQueue;
}
开发者ID:ZixiangBoy,项目名称:SignalR-1,代码行数:7,代码来源:HttpRequestLifeTime.cs
示例20: TraceTransferScope
/// <summary>
/// Constructor used to initialize the class
/// </summary>
/// <param name="source">The source that we are tracing through as part of this scope</param>
/// <param name="name">The name of the activity that this scope represents</param>
public TraceTransferScope(TraceSource source, string name)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name");
}
this.source = source;
this.oldActivity = Trace.CorrelationManager.ActivityId;
this.name = name;
this.newActivity = Guid.NewGuid();
if (this.oldActivity != Guid.Empty)
{
this.source.TraceTransfer(0, string.Format("Transferring to {0}...", this.name), this.newActivity);
}
Trace.CorrelationManager.ActivityId = this.newActivity;
this.source.TraceEvent(TraceEventType.Start, 0, this.name);
}
开发者ID:britehouse,项目名称:toyota-tsusho-new,代码行数:32,代码来源:TraceTransferScope.cs
注:本文中的System.Diagnostics.TraceSource类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论