本文整理汇总了C#中ILog.DebugFormat方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.DebugFormat方法的具体用法?C# ILog.DebugFormat怎么用?C# ILog.DebugFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILog
的用法示例。
在下文中一共展示了ILog.DebugFormat方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModuleLoader
public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, AggregateCatalog> addToCatalog, Func<CompositionContainer, IEnumerable<Lazy<IModule, IModuleMetadata>>> getLazyModules, IFileSystem fileSystem, IAssemblyUtility assemblyUtility)
{
_resolver = resolver;
_logger = logger;
if (addToCatalog == null)
{
addToCatalog = (assembly, catalog) =>
{
try
{
var assemblyCatalog = new AssemblyCatalog(assembly);
catalog.Catalogs.Add(assemblyCatalog);
}
catch (Exception exception)
{
logger.DebugFormat("Module Loader exception: {0}", exception.Message);
}
};
}
_addToCatalog = addToCatalog;
if (getLazyModules == null)
{
getLazyModules = container => container.GetExports<IModule, IModuleMetadata>();
}
_getLazyModules = getLazyModules;
_fileSystem = fileSystem;
_assemblyUtility = assemblyUtility;
}
示例2: CallAllMethodsOnLog
protected void CallAllMethodsOnLog(ILog log)
{
Assert.IsTrue(log.IsDebugEnabled);
Assert.IsTrue(log.IsErrorEnabled);
Assert.IsTrue(log.IsFatalEnabled);
Assert.IsTrue(log.IsInfoEnabled);
Assert.IsTrue(log.IsWarnEnabled);
log.Debug("Testing DEBUG");
log.Debug("Testing DEBUG Exception", new Exception());
log.DebugFormat("Testing DEBUG With {0}", "Format");
log.Info("Testing INFO");
log.Info("Testing INFO Exception", new Exception());
log.InfoFormat("Testing INFO With {0}", "Format");
log.Warn("Testing WARN");
log.Warn("Testing WARN Exception", new Exception());
log.WarnFormat("Testing WARN With {0}", "Format");
log.Error("Testing ERROR");
log.Error("Testing ERROR Exception", new Exception());
log.ErrorFormat("Testing ERROR With {0}", "Format");
log.Fatal("Testing FATAL");
log.Fatal("Testing FATAL Exception", new Exception());
log.FatalFormat("Testing FATAL With {0}", "Format");
}
示例3: CloudProvisioning
/// <summary>IoC constructor.</summary>
public CloudProvisioning(ICloudConfigurationSettings settings, ILog log, ICloudProvisioningObserver provisioningObserver = null)
{
_log = log;
// try get settings and certificate
if (!CloudEnvironment.IsAvailable)
{
_log.WarnFormat("Provisioning: RoleEnvironment not available on worker {0}.", CloudEnvironment.PartitionKey);
return;
}
var currentDeploymentPrivateId = CloudEnvironment.AzureDeploymentId;
Maybe<X509Certificate2> certificate = Maybe<X509Certificate2>.Empty;
if (!String.IsNullOrWhiteSpace(settings.SelfManagementCertificateThumbprint))
{
certificate = CloudEnvironment.GetCertificate(settings.SelfManagementCertificateThumbprint);
}
// early evaluate management status for intrinsic fault states, to skip further processing
if (!currentDeploymentPrivateId.HasValue || !certificate.HasValue || string.IsNullOrWhiteSpace(settings.SelfManagementSubscriptionId))
{
_log.DebugFormat("Provisioning: Not available because either the certificate or the subscription was not provided correctly.");
return;
}
// detect dev fabric
if (currentDeploymentPrivateId.Value.StartsWith("deployment("))
{
_log.DebugFormat("Provisioning: Not available in dev fabric instance '{0}'.", CloudEnvironment.AzureCurrentInstanceId.GetValue("N/A"));
return;
}
// ok
_provisioning = new AzureProvisioning(settings.SelfManagementSubscriptionId, certificate.Value, provisioningObserver);
_currentDeployment = new AzureCurrentDeployment(currentDeploymentPrivateId.Value, settings.SelfManagementSubscriptionId, certificate.Value, provisioningObserver);
}
示例4: IsLogin
public static bool IsLogin(IContextService context
, System.Security.Principal.IPrincipal user
, ILog log)
{
if (context == null || context.Current == null)
{
if (log != null && log.IsDebugEnabled)
log.DebugFormat("[Deny]IContextService={0}|Current={1}|IsAuthenticated={2}|Name={3}"
, context
, context != null ? context.Current : null
, user.Identity.IsAuthenticated
, user.Identity.Name);
return false;
}
return true;
}
示例5: LogFormat
public static void LogFormat(this IEnableLog This, ILog logger, LogType type, string format, params object[] args)
{
switch (type)
{
case LogType.Debug:
logger.DebugFormat(format, args);
break;
case LogType.Error:
logger.ErrorFormat(format, args);
break;
case LogType.Fatal:
logger.FatalFormat(format, args);
break;
case LogType.Info:
logger.InfoFormat(format, args);
break;
case LogType.Warn:
logger.WarnFormat(format, args);
break;
}
}
示例6: InternalTest
private static void InternalTest(ILog log)
{
const string message = "add record in db";
log.Debug(message);
log.Debug(message, new Exception());
log.DebugFormat(message);
log.Error(message);
log.Error(message, new Exception());
log.ErrorFormat(message);
log.Fatal(message);
log.Fatal(message, new Exception());
log.Info(message);
log.Info(message, new Exception());
log.InfoFormat(message);
log.Warn(message);
log.Warn(message, new Exception());
log.WarnFormat(message);
Console.WriteLine(log.IsDebugEnabled);
Console.WriteLine(log.IsErrorEnabled);
Console.WriteLine(log.IsFatalEnabled);
Console.WriteLine(log.IsInfoEnabled);
Console.WriteLine(log.IsWarnEnabled);
//log.TryLogFail(ErrorAction).Exception(e => Console.WriteLine(e.Message));
//log.TryLogFail(SuccessAction).Success(()=>{});
}
示例7: Execute
public void Execute()
{
RedisConfig.DisableVerboseLogging = true;
LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true);
log = LogManager.GetLogger(GetType());
RedisConfig.DefaultReceiveTimeout = 10000;
OnSetUp();
using (var sentinel = CreateSentinel())
{
if (UseRedisManagerPool)
{
sentinel.RedisManagerFactory = (masters, slaves) =>
new RedisManagerPool(masters);
}
var redisManager = sentinel.Start();
int i = 0;
var clientTimer = new Timer
{
Interval = MessageInterval,
Enabled = true
};
clientTimer.Elapsed += (sender, args) =>
{
log.Debug("clientTimer.Elapsed: " + (i++));
try
{
string key = null;
using (var master = (RedisClient)redisManager.GetClient())
{
var counter = master.Increment("key", 1);
key = "key" + counter;
log.DebugFormat("Set key {0} in read/write client #{1}@{2}", key, master.Id, master.GetHostString());
master.SetValue(key, "value" + 1);
}
using (var readOnly = (RedisClient)redisManager.GetReadOnlyClient())
{
log.DebugFormat("Get key {0} in read-only client #{1}@{2}", key, readOnly.Id, readOnly.GetHostString());
var value = readOnly.GetValue(key);
log.DebugFormat("{0} = {1}", key, value);
}
}
catch (ObjectDisposedException ex)
{
log.DebugFormat("ObjectDisposedException detected, disposing timer...");
clientTimer.Dispose();
}
catch (Exception ex)
{
log.Error("Error in Timer", ex);
}
if (i % 10 == 0)
log.Debug(RedisStats.ToDictionary().Dump());
};
log.Debug("Sleeping for 5000ms...");
Thread.Sleep(5000);
log.Debug("Failing over master...");
var masterHost = sentinel.ForceMasterFailover();
log.Debug("{0} was failed over".Fmt(masterHost));
log.Debug("Sleeping for 20000ms...");
Thread.Sleep(20000);
try
{
var debugConfig = sentinel.GetMaster();
using (var master = new RedisClient(debugConfig))
{
log.Debug("Putting master '{0}' to sleep for 35 seconds...".Fmt(master.GetHostString()));
master.DebugSleep(35);
}
}
catch (Exception ex)
{
log.Error("Error retrieving master for DebugSleep()", ex);
}
log.Debug("After DEBUG SLEEP... Sleeping for 5000ms...");
Thread.Sleep(5000);
log.Debug("RedisStats:");
log.Debug(RedisStats.ToDictionary().Dump());
System.Console.ReadLine();
}
OnTearDown();
}
示例8: Initialize
/// <summary>
/// Initializes the bootstrap with the configuration, config resolver and log factory.
/// </summary>
/// <param name="serverConfigResolver">The server config resolver.</param>
/// <param name="loggerFactory">The logger factory.</param>
/// <returns></returns>
public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILoggerFactory loggerFactory)
{
if (m_Initialized)
throw new Exception("The server had been initialized already, you cannot initialize it again!");
if (loggerFactory != null && !string.IsNullOrEmpty(m_Config.LoggerFactory))
{
throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "loggerFactory");
}
if(loggerFactory == null)
{
loggerFactory = GetBootstrapLoggerFactory(m_Config.LoggerFactory);
}
m_GlobalLog = loggerFactory.GetCurrentClassLogger();
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
m_AppServers = new List<IManagedApp>(m_Config.Servers.Count());
IManagedApp serverManager = null;
//Initialize servers
foreach (var config in m_Config.Servers)
{
var serverConfig = config;
if (serverConfigResolver != null)
serverConfig = serverConfigResolver(config);
IManagedApp appServer;
try
{
var serverType = serverConfig.ServerType;
if(string.IsNullOrEmpty(serverType) && !string.IsNullOrEmpty(serverConfig.ServerTypeName))
{
var serverTypeProvider = m_Config.ServerTypes.FirstOrDefault(
t => t.Name.Equals(serverConfig.ServerTypeName, StringComparison.OrdinalIgnoreCase));
if (serverTypeProvider != null)
serverType = serverTypeProvider.Type;
}
if (string.IsNullOrEmpty(serverType))
throw new Exception("No server type configured or the configured server type was not found.");
appServer = CreateWorkItemInstance(serverType);
var serverMetadata = appServer.GetAppServerMetadata();
if (serverMetadata.IsServerManager)
serverManager = appServer;
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been created!", serverConfig.Name);
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", serverConfig.Name), e);
return false;
}
var exceptionSource = appServer as IExceptionSource;
if(exceptionSource != null)
exceptionSource.ExceptionThrown += new EventHandler<ErrorEventArgs>(exceptionSource_ExceptionThrown);
var setupResult = false;
try
{
setupResult = SetupWorkItemInstance(appServer, serverConfig);
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
}
catch (Exception e)
{
m_GlobalLog.Error(e);
setupResult = false;
}
if (!setupResult)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error("Failed to setup server instance!");
return false;
}
//.........这里部分代码省略.........
示例9: DefaultWriteLogEvent
protected static void DefaultWriteLogEvent(ILog commonLog, TraceEventType traceEventType, String message, Exception ex)
{
switch (traceEventType)
{
case TraceEventType.Critical:
commonLog.FatalFormat(message, ex);
break;
case TraceEventType.Error:
commonLog.ErrorFormat(message, ex);
break;
case TraceEventType.Warning:
commonLog.WarnFormat(message, ex);
break;
case TraceEventType.Information:
commonLog.InfoFormat(message, ex);
break;
case TraceEventType.Verbose:
commonLog.TraceFormat(message, ex);
break;
case TraceEventType.Start:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Stop:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Suspend:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Resume:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Transfer:
commonLog.DebugFormat(message, ex);
break;
default:
throw new ArgumentOutOfRangeException("traceEventType");
}
}
示例10: Initialize
/// <summary>
/// Initializes the bootstrap with the configuration, config resolver and log factory.
/// </summary>
/// <param name="serverConfigResolver">The server config resolver.</param>
/// <param name="logFactory">The log factory.</param>
/// <returns></returns>
public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
{
if (m_Initialized)
throw new Exception("The server had been initialized already, you cannot initialize it again!");
if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
{
throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
}
IEnumerable<WorkItemFactoryInfo> workItemFactories;
using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
{
var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory();
logFactory = bootstrapLogFactory.ExportFactory.CreateExport<ILogFactory>();
LogFactory = logFactory;
m_GlobalLog = logFactory.GetLog(this.GetType().Name);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
try
{
workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(e);
return false;
}
}
m_AppServers = new List<IWorkItem>(m_Config.Servers.Count());
IWorkItem serverManager = null;
//Initialize servers
foreach (var factoryInfo in workItemFactories)
{
IWorkItem appServer;
try
{
appServer = CreateWorkItemInstance(factoryInfo.ServerType, factoryInfo.StatusInfoMetadata);
if (factoryInfo.IsServerManager)
serverManager = appServer;
else if (!(appServer is IsolationAppServer))//No isolation
{
//In isolation mode, cannot check whether is server manager in the factory info loader
if (TypeValidator.IsServerManagerType(appServer.GetType()))
serverManager = appServer;
}
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been created!", factoryInfo.Config.Name);
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", factoryInfo.Config.Name), e);
return false;
}
var exceptionSource = appServer as IExceptionSource;
if(exceptionSource != null)
exceptionSource.ExceptionThrown += new EventHandler<ErrorEventArgs>(exceptionSource_ExceptionThrown);
var setupResult = false;
try
{
setupResult = SetupWorkItemInstance(appServer, factoryInfo);
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
}
catch (Exception e)
{
m_GlobalLog.Error(e);
setupResult = false;
}
if (!setupResult)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error("Failed to setup server instance!");
return false;
//.........这里部分代码省略.........
示例11: CanLogMessageWithException
protected virtual void CanLogMessageWithException(ILog log)
{
log.TraceFormat("Hi {0}", new ArithmeticException(), "dude");
log.DebugFormat("Hi {0}", new ArithmeticException(), "dude");
log.InfoFormat("Hi {0}", new ArithmeticException(), "dude");
log.WarnFormat("Hi {0}", new ArithmeticException(), "dude");
log.ErrorFormat("Hi {0}", new ArithmeticException(), "dude");
log.FatalFormat("Hi {0}", new ArithmeticException(), "dude");
}
示例12: SetWritable
public static void SetWritable(ILog log, string path)
{
if (!File.Exists(path))
{
return;
}
FileAttributes attributes = File.GetAttributes(path);
if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
// Make the file RW
attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
File.SetAttributes(path, attributes);
log.DebugFormat("The {0} file is no longer RO.", path);
}
}
示例13: Initialize
/// <summary>
/// Initializes the bootstrap with the configuration, config resolver and log factory.
/// </summary>
/// <param name="serverConfigResolver">The server config resolver.</param>
/// <param name="logFactory">The log factory.</param>
/// <returns></returns>
public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
{
if (m_Initialized)
throw new Exception("The server had been initialized already, you cannot initialize it again!");
if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
{
throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
}
IEnumerable<WorkItemFactoryInfo> workItemFactories;
using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
{
var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory();
logFactory = bootstrapLogFactory.ExportFactory.CreateExport<ILogFactory>();
LogFactory = logFactory;
m_GlobalLog = logFactory.GetLog(this.GetType().Name);
try
{
workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(e);
return false;
}
}
m_AppServers = new List<IWorkItem>(m_Config.Servers.Count());
//Initialize servers
foreach (var factoryInfo in workItemFactories)
{
IWorkItem appServer;
try
{
appServer = CreateWorkItemInstance(factoryInfo.ServerType);
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been created!", factoryInfo.Config.Name);
}
catch (Exception e)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", factoryInfo.Config.Name), e);
return false;
}
var setupResult = false;
try
{
setupResult = SetupWorkItemInstance(appServer, factoryInfo);
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
}
catch (Exception e)
{
m_GlobalLog.Error(e);
setupResult = false;
}
if (!setupResult)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error("Failed to setup server instance!");
return false;
}
m_AppServers.Add(appServer);
}
if (!m_Config.DisablePerformanceDataCollector)
{
m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, logFactory);
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
}
if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.Debug("The Bootstrap has been initialized!");
m_Initialized = true;
return true;
//.........这里部分代码省略.........
示例14: AbstractXBeeDevice
/**
* Class constructor. Instantiates a new {@code RemoteXBeeDevice} object
* with the given local {@code XBeeDevice} which contains the connection
* interface to be used.
*
* @param localXBeeDevice The local XBee device that will behave as
* connection interface to communicate with this
* remote XBee device.
* @param addr64 The 64-bit address to identify this XBee device.
* @param addr16 The 16-bit address to identify this XBee device. It might
* be {@code null}.
* @param id The node identifier of this XBee device. It might be
* {@code null}.
*
* @throws ArgumentException If {@code localXBeeDevice.isRemote() == true}.
* @throws ArgumentNullException If {@code localXBeeDevice == null} or
* if {@code addr64 == null}.
*
* @see #AbstractXBeeDevice(IConnectionInterface)
* @see #AbstractXBeeDevice(String, int)
* @see #AbstractXBeeDevice(String, SerialPortParameters)
* @see #AbstractXBeeDevice(XBeeDevice, XBee64BitAddress)
* @see #AbstractXBeeDevice(String, int, int, int, int, int)
* @see com.digi.xbee.api.models.XBee16BitAddress
* @see com.digi.xbee.api.models.XBee64BitAddress
*/
public AbstractXBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64,
XBee16BitAddress addr16, String id)
{
if (localXBeeDevice == null)
throw new ArgumentNullException("Local XBee device cannot be null.");
if (addr64 == null)
throw new ArgumentNullException("XBee 64-bit address of the device cannot be null.");
if (localXBeeDevice.IsRemote)
throw new ArgumentException("The given local XBee device is remote.");
XBeeProtocol = XBeeProtocol.UNKNOWN;
this.localXBeeDevice = localXBeeDevice;
this.connectionInterface = localXBeeDevice.GetConnectionInterface();
this.xbee64BitAddress = addr64;
this.xbee16BitAddress = addr16;
if (addr16 == null)
xbee16BitAddress = XBee16BitAddress.UNKNOWN_ADDRESS;
this.nodeID = id;
this.logger = LogManager.GetLogger(this.GetType());
logger.DebugFormat(ToString() + "Using the connection interface {0}.",
connectionInterface.GetType().Name);
this.IOPacketReceiveListener = new CustomPacketReceiveListener(this);
}