本文整理汇总了C#中System.Diagnostics.TraceSource类的典型用法代码示例。如果您正苦于以下问题:C# TraceSource类的具体用法?C# TraceSource怎么用?C# TraceSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceSource类属于System.Diagnostics命名空间,在下文中一共展示了TraceSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: RMQServiceBusInterface
RMQServiceBusInterface( ServiceBusClient dispatcher, TraceSource tracer )
{
if (dispatcher == null)
throw new ArgumentNullException("entity");
Process = dispatcher;
this.Tracer = tracer;
}
示例3: SqlSender
public SqlSender(string connectionString, string tableName, TraceSource traceSource, IDbProviderFactory dbProviderFactory)
{
_connectionString = connectionString;
_insertDml = BuildInsertString(tableName);
_trace = traceSource;
_dbProviderFactory = dbProviderFactory;
}
示例4: SqlInstaller
public SqlInstaller(string connectionString, string tableNamePrefix, int tableCount, TraceSource traceSource)
{
_connectionString = connectionString;
_messagesTableNamePrefix = tableNamePrefix;
_tableCount = tableCount;
_trace = traceSource;
}
示例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");
}
示例6: ObservableDbOperation
public ObservableDbOperation(string connectionString, string commandText, TraceSource traceSource, IDbProviderFactory dbProviderFactory, IDbBehavior dbBehavior)
: base(connectionString, commandText, traceSource, dbProviderFactory)
{
_dbBehavior = dbBehavior ?? this;
InitEvents();
}
示例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");
}
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}
示例12: AgentMessageTable
private AgentMessageTable()
{
id = Guid.NewGuid().ToString();
log = new TraceSource(name);
Hashtable t = new Hashtable();
messageTable = Hashtable.Synchronized(t);
}
示例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;
}
}
示例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;
}
示例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} 个");
}