本文整理汇总了C#中log4net.ILog.Error方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.Error方法的具体用法?C# ILog.Error怎么用?C# ILog.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类log4net.ILog
的用法示例。
在下文中一共展示了ILog.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test1
internal static void Test1(ILog logger)
{
IList<string> myList = new List<string>();
myList.Add("item1");
myList.Add("item2");
IDictionary<string, string> myDictionary = new Dictionary<string, string>();
myDictionary["k1"] = "v1";
myDictionary["k2"] = "v2";
HttpField.HttpInstance.Set(HttpFieldName.ResponseHeaders, myList);
HttpField.HttpInstance.Set(HttpFieldName.RequestHeaders, myDictionary);
logger.Error("there's been an error");
// log4net doesn't give exceptions any special treatment...
// also dotnet won't generate a stacktrace for an exception til we throw it...
logger.Error(new ArgumentException("Fake Error Thrown"));
try
{
string dodgy = null;
Console.WriteLine(dodgy.Equals("that", StringComparison.InvariantCulture));
}
catch (NullReferenceException e)
{
logger.Error(e);
}
HttpField.HttpInstance.Clear();
logger.Info("non exception");
}
示例2: Main
static void Main( string[] args )
{
//--- Initialise log4net
log4net.Config.XmlConfigurator.Configure();
log_ = log4net.LogManager.GetLogger( typeof( Program ) );
//--- Create the interface to Cortex
cortex_ = CortexInterface.Instance;
//--- Self host the WebAPI
HttpSelfHostServer server = null;
try
{
//--- Set up server configuration
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration( _baseAddress );
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{object_id}/{port_id}",
defaults: new { object_id = RouteParameter.Optional, port_id = RouteParameter.Optional }
);
//--- Create the server
server = new HttpSelfHostServer( config );
//--- Start listening
server.OpenAsync().Wait();
log_.Info( "Listening on " + _baseAddress + " Hit ENTER to exit..." );
Console.ReadLine();
}
catch ( Exception e )
{
log_.Error( "Could not start server: " + e.GetBaseException().Message );
log_.Error( "Hit ENTER to exit..." );
Console.ReadLine();
}
finally
{
if ( server != null )
{
//--- Stop listening
server.CloseAsync().Wait();
}
}
}
示例3: Error
public static void Error(string message, Exception ex, ILog log)
{
if (log.IsErrorEnabled)
{
log.Error(message, ex);
}
}
示例4: Error
/// <summary>
/// The error.
/// </summary>
/// <param name="log">
/// The log.
/// </param>
/// <param name="message">
/// The message.
/// </param>
public static void Error(ILog log, string message)
{
if (log != null)
{
log.Error(message);
}
}
示例5: WebState
static WebState() {
try {
#region Configure logging.
try {
log4net.Config.XmlConfigurator.Configure();
logger = log4net.LogManager.GetLogger(LOGGER_NAME);
}
catch (Exception logExcp) {
Console.WriteLine("Exception SIPProxyState Configure Logging. " + logExcp.Message);
}
#endregion
CRMStorageType = (ConfigurationManager.AppSettings[m_storageTypeKey] != null) ? StorageTypesConverter.GetStorageType(ConfigurationManager.AppSettings[m_storageTypeKey]) : StorageTypes.Unknown;
CRMStorageConnStr = ConfigurationManager.AppSettings[m_connStrKey];
if (CRMStorageType == StorageTypes.Unknown || CRMStorageConnStr.IsNullOrBlank()) {
logger.Error("The SIPSorcery.CRM.Web does not have any persistence settings configured.");
}
XmlNode validationRulesNode = (XmlNode)ConfigurationManager.GetSection(CUSTOMER_VALIDATION_RULES);
if (validationRulesNode != null) {
foreach (XmlNode validationNode in validationRulesNode) {
ValidationRules.Add(validationNode.SelectSingleNode("field").InnerText, validationNode.SelectSingleNode("rule").InnerText);
}
}
}
catch (Exception excp) {
logger.Error("Exception WebState. " + excp.Message);
}
}
示例6: Client
public Client(int id, Config cfg, SynchronizationContext ctx)
{
ClientStatisticsGatherer = new ClientStatisticsGatherer();
_ctx = ctx;
_id = id;
Data = new TestData(this);
IsStopped = false;
_log = LogManager.GetLogger("Client_" + _id);
_log.Debug("Client created");
Configure(cfg);
if (String.IsNullOrEmpty(_login))
{
const string err = "Login command is not specified!!! Can't do any test.";
_log.Error(err);
throw new Exception(err);
}
_ajaxHelper = new AjaxHelper(new AjaxConn(_login, cfg.ServerIp, cfg.AjaxPort, _ctx));
_webSock = new WebSockConn(_login, cfg.ServerIp, cfg.WsPort, ctx);
_webSock.CcsStateChanged += WsOnCcsStateChanged;
_webSock.InitializationFinished += () => _testMng.GetTest<LoginTest>().OnClientInitialized();
_testMng.SetEnv(_login, _ajaxHelper.AjaxConn, _webSock);
}
示例7: Log
public static void Log(ILog logger, string message, string action)
{
//MDC.Set("user", ClientInfo.getInstance().LoggedUser.Name);
log4net.GlobalContext.Properties["user"] = "admin";
log4net.GlobalContext.Properties["action"] = action;
logger.Error(message); //now log error
}
示例8: MiniSSCIIServoController
/**
* <summary>
* Constructor with port name and open the port.
* Also initializes servo channels to center
* </summary>
*
* <param name="portName">Name of the serial port</param>
* <param name="channels">Channels to center on construction</param>
*/
protected MiniSSCIIServoController(string portName, ICollection<uint> channels)
{
log = LogManager.GetLogger(this.GetType());
log.Debug(this.ToString() + " constructed.");
activeChannels = channels;
try
{
port = new SerialPort(portName);
port.Open();
port.BaudRate = 9600;
port.NewLine = string.Empty + Convert.ToChar(13);
port.Handshake = System.IO.Ports.Handshake.None;
port.BaseStream.Flush();
port.ReadTimeout = 1000;
inactive = false;
foreach (uint ch in channels)
{
ServoMovementCommand smc = new ServoMovementCommand(ch, 128);
sendCommand(smc);
}
log.Info("Initiating all servos to center.");
}
catch (IOException ex)
{
log.Error("Could not open Servo Controller Port on " + portName, ex);
inactive = true;
}
}
示例9: WaitForResultOfRequest
protected void WaitForResultOfRequest(ILog logger, string workerTypeName, IOperation operation, Guid subscriptionId, string certificateThumbprint, string requestId)
{
OperationResult operationResult = new OperationResult();
operationResult.Status = OperationStatus.InProgress;
bool done = false;
while (!done)
{
operationResult = operation.StatusCheck(subscriptionId, certificateThumbprint, requestId);
if (operationResult.Status == OperationStatus.InProgress)
{
string logMessage = string.Format(CultureInfo.CurrentCulture, "{0} '{1}' submitted a deployment request with ID '{2}', the operation was found to be in process, waiting for '{3}' seconds.", workerTypeName, this.Id, requestId, FiveSecondsInMilliseconds / 1000);
logger.Info(logMessage);
Thread.Sleep(FiveSecondsInMilliseconds);
}
else
{
done = true;
}
}
if (operationResult.Status == OperationStatus.Failed)
{
string logMessage = string.Format(CultureInfo.CurrentCulture, "{0} '{1}' submitted a deployment request with ID '{2}' and it failed. The code was '{3}' and message '{4}'.", workerTypeName, this.Id, requestId, operationResult.Code, operationResult.Message);
logger.Error(logMessage);
}
else if (operationResult.Status == OperationStatus.Succeeded)
{
string logMessage = string.Format(CultureInfo.CurrentCulture, "{0} '{1}' submitted a deployment request with ID '{2}' and it succeeded. The code was '{3}' and message '{4}'.", workerTypeName, this.Id, requestId, operationResult.Code, operationResult.Message);
logger.Info(logMessage);
}
}
示例10: SIPSoftPhoneState
static SIPSoftPhoneState()
{
try
{
#region Configure logging.
try
{
log4net.Config.XmlConfigurator.Configure();
logger = log4net.LogManager.GetLogger(LOGGER_NAME);
}
catch (Exception logExcp)
{
Console.WriteLine("Exception SIPSoftPhoneState Configure Logging. " + logExcp.Message);
}
#endregion
if (ConfigurationManager.GetSection(SIPSOFTPHONE_CONFIGNODE_NAME) != null) {
m_sipSoftPhoneConfigNode = (XmlNode)ConfigurationManager.GetSection(SIPSOFTPHONE_CONFIGNODE_NAME);
}
if (m_sipSoftPhoneConfigNode != null) {
SIPSocketsNode = m_sipSoftPhoneConfigNode.SelectSingleNode(SIPSOCKETS_CONFIGNODE_NAME);
}
STUNServerHostname = ConfigurationManager.AppSettings[STUN_SERVER_KEY];
}
catch (Exception excp)
{
logger.Error("Exception SIPSoftPhoneState. " + excp.Message);
throw;
}
}
示例11: Show
/// <summary>
/// 异常日志信息
/// </summary>
/// <param name="text"></param>
/// <param name="caption"></param>
/// <param name="buttons"></param>
/// <param name="icon"></param>
/// <param name="ex"></param>
/// <param name="FormType"></param>
/// <returns></returns>
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, Exception ex,Type FormType)
{
log = LogManager.GetLogger(FormType);
log.Error(ex);
return DevExpress.XtraEditors.XtraMessageBox.Show(text, caption, buttons, icon);
}
示例12: Main
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
//if (log4net.LogManager.GetCurrentLoggers().Length == 0)
{
log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
}
logger = log4net.LogManager.GetLogger(typeof(Program));
logger.Info("LogzAppender working!!");
logger.Info("This is another message!!");
try
{
var a = 0;
a += 0;
var b = 5 / a;
}
catch (Exception ex)
{
logger.Error(new Dictionary<String, String>() {
{ "message", "test message" },
{ "gilly", "barr" }
}, ex);
}
Console.ReadKey(true);
}
示例13: Init
private void Init(NameValueCollection appSettings, string collectionUrl)
{
_logger = LogManager.GetLogger(GetType());
try
{
collectionUrl = string.IsNullOrWhiteSpace(collectionUrl) ? null : collectionUrl.TrimEnd('/');
var defaultUpdateUrl = collectionUrl == null ? null : string.Format("{0}/update", collectionUrl);
var defaultQueryUrl = collectionUrl == null ? null : string.Format("{0}/query", collectionUrl);
UpdateUrl = GetValueFromAppSettings(appSettings, SettingCollectionUpdateUrl, defaultUpdateUrl);
QueryUrl = GetValueFromAppSettings(appSettings, SettingCollectionQueryUrl, defaultQueryUrl);
if (UpdateUrl == null || QueryUrl == null)
{
throw new TypeInitializationException(GetType().FullName,
new ArgumentNullException(SettingCollectionUpdateUrl,
string.Format(
"The app setting {0} should be configured to the base url of a solr core/collection, e.g.: http://localhost:8983/solr/collectionName, which supports both the /update and /query request handlers. Alternatively, explicit urls can be set for query and update handlers with the app settings {1} and {2}, respectively",
SettingCollectionUrl, SettingCollectionQueryUrl, SettingCollectionUpdateUrl)));
}
}
catch (Exception ex)
{
_logger.Error("Could not initialize solr configuration", ex);
throw;
}
}
示例14: GetShortenLink
public static String GetShortenLink(String shareLink, ILog log)
{
var uri = new Uri(shareLink);
var bitly = string.Format(BitlyUrl, Uri.EscapeDataString(uri.ToString()));
XDocument response;
try
{
response = XDocument.Load(bitly);
}
catch (Exception e)
{
if (log != null) { log.Error(e); }
throw new InvalidOperationException(e.Message, e);
}
var status = response.XPathSelectElement("/response/status_code").Value;
if (status != ((int)HttpStatusCode.OK).ToString(CultureInfo.InvariantCulture))
{
throw new InvalidOperationException(Resources.Resource.ErrorBadRequest + " (" + status + ")");
}
var data = response.XPathSelectElement("/response/data/url");
return data.Value;
}
示例15: LogRestError
public static void LogRestError(ILog logger, IRestResponse restResponse, string errorHeading)
{
if (logger != null && restResponse != null)
{
var stringBuilder = BuildLoggingString(restResponse, errorHeading);
logger.Error(stringBuilder.ToString());
}
}
开发者ID:sportingsolutions,项目名称:SS.Integration.UnifiedDataAPIClient.DotNet,代码行数:8,代码来源:RestErrorHelper.cs