当前位置: 首页>>代码示例>>C#>>正文


C# ILog.Error方法代码示例

本文整理汇总了C#中ILog.Error方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.Error方法的具体用法?C# ILog.Error怎么用?C# ILog.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILog的用法示例。


在下文中一共展示了ILog.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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");
        }
开发者ID:afyles,项目名称:NServiceBus,代码行数:28,代码来源:BaseLoggerFactoryTests.cs

示例2: GetXmppHosts

 public XmppHost[] GetXmppHosts(IPAddress[] dnsServers, string domain, ILog log)
 {
     var dnsQueryRequest = new DnsQueryRequest();
     string record = "_xmpp-server._tcp." + domain;
     bool dnsServerWasReached = false;
     foreach (IPAddress address in dnsServers) {
         DnsQueryResponse queryResponse = null;
         try {
             queryResponse = dnsQueryRequest.Resolve(address.ToString(), record, NsType.SRV, NsClass.INET, ProtocolType.Udp);
         }
         catch(SocketException ex) {
             log.Error("Dns server unreachable. " + ex);
             continue;
         }
         dnsServerWasReached = true;
         if (queryResponse == null || queryResponse.Answers == null || queryResponse.Answers.Length <= 0) continue;
         var hosts = new List<XmppHost>();
         foreach (IDnsRecord answer in queryResponse.Answers) {
             var srvRecord = (SrvRecord) answer;
             try {
                 IPHostEntry ipHostEntry = System.Net.Dns.GetHostEntry(srvRecord.HostName);
                 foreach (IPAddress ipAddress in ipHostEntry.AddressList) {
                     hosts.Add(new XmppHost(ipHostEntry.HostName, ipAddress, srvRecord.Port));
                 }
             }
             catch (SocketException ex) {
                 if (ex.SocketErrorCode == SocketError.HostNotFound) {
                     log.Warn(ex);
                 }
                 else {
                     throw;
                 }
             }
             catch (Exception ex) {
                 log.Error(ex);
                 throw;
             }
         }
         if(hosts.Count == 0) {
             throw new SocketException(11001); //Host not found
         }
         return hosts.ToArray();
     }
     if (!dnsServerWasReached) {
         throw new SocketException(10060);
     }
     //couldn't locate the service via dns, assume the domain is the host.
     try {
         IPHostEntry defaultHostEntry = System.Net.Dns.GetHostEntry(domain);
         var hosts = new List<XmppHost>();
         foreach (IPAddress ipAddress in defaultHostEntry.AddressList) {
             hosts.Add(new XmppHost(defaultHostEntry.HostName, ipAddress, 5222)); //5222 default XmppPort
         }
         return hosts.ToArray();
     }
     catch(SocketException ex) {
         log.Error(ex);
         throw;
     }
 }
开发者ID:Andrea,项目名称:nxmpp,代码行数:60,代码来源:XmppHostsLookup.cs

示例3: SafeCloseClientSocket

        /// <summary>
        /// Safes the close client socket.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="logger">The logger.</param>
        public static void SafeCloseClientSocket(this Socket client, ILog logger)
        {
            if(client == null)
                return;

            if (!client.Connected)
                return;
            
            try
            {
                client.Shutdown(SocketShutdown.Both);
            }
            catch(ObjectDisposedException)
            {
            }
            catch(Exception e)
            {
                if(logger != null)
                    logger.Error(e);
            }
            
            try
            {
                client.Close();
            }
            catch(ObjectDisposedException)
            {
            }
            catch(Exception e)
            {
                if(logger != null)
                    logger.Error(e);
            }
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:39,代码来源:SocketEx.cs

示例4: Start

        public void Start(ConcoctConfiguration config, ILog log)
        {
            try {
                var site = Assembly.LoadFrom(config.ApplicationAssemblyPath);
                var types = site.GetTypes();
                var httpApplicationType = types.Where(x => x.IsTypeOf<HttpApplication>()).First();

                FileRouteHandler.MapPath = path => path.Replace("~", config.WorkingDirectory);

                host = MvcHost.Create(
                    config.GetEndPoint(),
                    config.VirtualDirectoryOrPrefix,
                    config.WorkingDirectory,
                    httpApplicationType);

                if(config.LogRequests)
                    host.RequestHandler.BeginRequest += (_, e) => log.Info("{0} {1}", e.Request.HttpMethod, e.Request.Url);

                host.Start();
            } catch(FileNotFoundException appNotFound) {
                log.Error("Failed to locate {0}", appNotFound.FileName);
                throw new ApplicationException("Failed to load application");
            } catch(ReflectionTypeLoadException loadError) {
                log.Error("Error applications.");
                foreach(var item in loadError.LoaderExceptions) {
                    Console.Error.WriteLine(item);
                }
                throw new ApplicationException("Failed to load application", loadError);
            }
        }
开发者ID:drunkcod,项目名称:Concoct,代码行数:30,代码来源:ConcoctApplication.cs

示例5: Run

        public static void Run(ILog log)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, args) => log.Error(args.ExceptionObject.ToString());

            var configuration = new Configuration.Configuration();
            var host = new ServiceHost(new WebSiteService(), new Uri(string.Format("http://{0}:{1}", Environment.MachineName, configuration.WebSiteHost)));

            host.AddServiceEndpoint(typeof(IWebSiteService), new WebHttpBinding(), "")
                .Behaviors.Add(new WebHttpBehavior { DefaultOutgoingResponseFormat = WebMessageFormat.Json, DefaultOutgoingRequestFormat = WebMessageFormat.Json });
            host.Open();
            log.Info("Web communication host has been successfully opened");

            while (true)
            {

                try
                {
                    new AutomatedPostReview(log, configuration).Run();
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
                Thread.Sleep(configuration.Timeout);
            }
        }
开发者ID:ayezutov,项目名称:ReviewBoardUtilities,代码行数:26,代码来源:Program.cs

示例6: DownloadResult

        public DownloadResult( ILog logger, Stream zipContent )
        {
            File = new TemporaryFile( ".zip" );
            using( zipContent )
            using( var sw = System.IO.File.Open( File.Path, FileMode.Open ) )
                zipContent.CopyTo( sw );

            try
            {
                // open the zip file
                using( ZipFile zip = ZipFile.Read( File.Path ) )
                {
                    var manifestEntry = zip.Where( z => z.FileName == "manifest.xml" ).FirstOrDefault();
                    if( manifestEntry != null )
                    {
                        var ms = new MemoryStream();
                        manifestEntry.Extract( ms );
                        try
                        {
                            Manifest = HelpManifestData.Deserialize( ms );
                        }
                        catch( Exception ex )
                        {
                            logger.Error( "Unable to parse manifest", ex );
                            throw;
                        }
                    }
                }
            }
            catch( Exception ex )
            {
                logger.Error( "Unable to read downloaded help content as a zip file", ex );
                throw;
            }
        }
开发者ID:Invenietis,项目名称:ck-certified,代码行数:35,代码来源:DownloadResult.cs

示例7: Main

        private static int Main(string[] args)
        {
            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                LogFactory.IsVerbose = options.Verbose;
                Log = LogManager.GetCurrentClassLogger();
                try
                {
                    IReportBuilderFactory builderFactory = new ReportBuilderFactory();
                    var builder = builderFactory.Create();
                    builder.Build(options);
                }
                catch (AppException ex)
                {
                    Log.Error(ex.Message);
                    Log.Info("Error occurs. Run sign -help to get more info.", ex);
                    return ex.ErrorCode;
                }
                catch (Exception ex)
                {
                    Log.Error("Internal error. Run with -verbose to see more details");
                    Log.Info(ex.Message, ex);
                    return ErrorCodes.InternalError;
                }

                return ErrorCodes.Ok;
            }
            return ErrorCodes.ParserError;
        }
开发者ID:rjasica,项目名称:HtmlWarningsReportGenerator,代码行数:30,代码来源:Program.cs

示例8: IOWorker

 /// <summary>do io loop with tcpclient
 /// </summary>
 /// <param name="log"></param>
 /// <param name="server"></param>
 /// <param name="tcpClient"></param>
 public static void IOWorker(ILog log, TcpServerChannel server, TcpClient tcpClient)
 {
     //remoting core protocol
     //Preamble 4
     //MajorVersion 1
     //MinorVersion 1
     //ReadOperation 2
     //ReadContentDelimiter 2
     //ReadContentLength 4
     var headerLength = 4 + 1 + 1 + 2 + 2 + 4;
     var header = new byte[headerLength];
     NetworkStream stream = tcpClient.GetStream();
     stream.BeginRead(header, 0, header.Length, o =>
     {
         RemotingTcpProtocolHandle handle = null;
         try
         {
             var length = stream.EndRead(o);
             handle = length == headerLength ? Parse(header, stream) : null;
         }
         catch (Exception e)
         {
             handle = null;
             log.Error(e);
         }
         finally
         {
             Process(handle, log, server, tcpClient);
         }
     }, null);
 }
开发者ID:wsky,项目名称:top-link,代码行数:36,代码来源:TcpRemotingHelper.cs

示例9: Deploy

        public bool Deploy(ZipPackage package, ILog logger)
        {
            var options = package.GetPackageOptions<XCopyOptions>();

            if (!_fileSystem.DirectoryExists(options.Destination))
            {
                logger.Error("{0} doesn't exist. Please create the folder before deploying!");

                return false;
            }

            logger.Info("Deploying xcopy package to {0}".Fmt(options.Destination));

            foreach (var file in package.GetFiles())
            {
                _fileSystem.EnsureDirectoryExists(options.Destination);

                using (var stream = file.GetStream())
                {
                    var destination = Path.Combine(options.Destination, file.Path);

                    new FileInfo(destination).Directory.Create(); // ensure directory is created
                    FileStream targetFile = File.OpenWrite(destination);
                    stream.CopyTo(targetFile);
                    targetFile.Close();
                }
            }

            return true;
        }
开发者ID:tobiaszuercher,项目名称:PowerDeploy,代码行数:30,代码来源:XCopyDeployer.cs

示例10: SendErrorEmail

        private static void SendErrorEmail(string jobName, Exception ex, ILog log)
        {
            var username = CloudConfigurationManager.GetSetting("sendgrid-username");
            var pass = CloudConfigurationManager.GetSetting("sendgrid-pass");

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(pass))
            {
                log.Error("Could not send email notification. Check username or password settings");
            }

            try
            {
                var sgMessage = SendGrid.GetInstance();
                sgMessage.From = new MailAddress("[email protected]", "Smithers Job Notifications");
                sgMessage.Subject = "Smithers Error Notification";
                sgMessage.AddTo("[email protected]");
                sgMessage.Html = string.Format("Error: {0} failed at {1} with exception <strong>{2}</strong><br><br> {3}", jobName, ex.Source,
                                               ex.Message, ex.StackTrace);

                var transport = SMTP.GetInstance(new NetworkCredential(username, pass));
                transport.Deliver(sgMessage);
            }
            catch (Exception mailException)
            {
                log.ErrorFormat("Error: Email send failed at {0} with exception {1} {2}", mailException,
                                mailException.Source, mailException.Message, mailException.StackTrace);
            }
        }
开发者ID:ucdavis,项目名称:Smithers,代码行数:28,代码来源:LoggerExtensions.cs

示例11: WriteSomeLogs

        private static void WriteSomeLogs(ILog logTunnel)
        {
            using (logTunnel.CreateScope("Starting somthing"))
            {
                logTunnel.Info("Test LogEntry {IntValue} {StringValue}", new
                                                                            {
                                                                                IntValue = 5,
                                                                                StringValue = "MyValue",
                                                                                Complex =
                                                                                    new ComplexData()
                                                                                    {
                                                                                        Complex2 =
                                                                                            new ComplexData()
                                                                                    },
                                                                            });

                logTunnel.Warning("My Warning");

                logTunnel.Log("Custom", "Non spesific log title");

                logTunnel.Error("Test LogEntry {*}", new
                                                        {
                                                            IntValue = 5,
                                                            StringValue = "MyValue",
                                                            Complex = new ComplexData()
                                                                      {
                                                                          //ExtraProp = 2,
                                                                          Complex2 = new ComplexDataDerived(),
                                                                      }
                                                        });

            }
        }
开发者ID:ronenbarak,项目名称:Whitelog,代码行数:33,代码来源:Program.cs

示例12: Main

        static void Main(string[] args)
        {
            _log = LogManager.GetLogger("Queaso.ConsoleClient.Main");
            try
            {
                _log.Info(l => l("Start client application..."));

                _log.Info(l => l("Exercise 1 - Work with ChannelFactory & Channel"));

                Exercise1();

                _log.Info(l => l("Exercise 2 - Work with Client Proxies"));
                
                Exercise2();

                _log.Info(l => l("Behaviours"));

                var customerProxy = new CustomerProxy();
                customerProxy.IsThisAnException();

                Thread.Sleep(50);

                
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                throw ex;
            }
        
        }
开发者ID:RubyGonzalez,项目名称:Queaso.Samples,代码行数:31,代码来源:Program.cs

示例13: LogError

        public static void LogError(ILog logger, Exception ex)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");
            if (ex == null)
                throw new ArgumentNullException("ex");

            logger.Error(ex.GetType().Name + " - " + ex.Message);
            String prefix = " ";
            while (ex.InnerException != null)
            {
                prefix += " ";
                logger.Error(prefix + ex.Message);
                ex = ex.InnerException;
            }
            logger.Error(ex.StackTrace);
        }
开发者ID:ViniciusConsultor,项目名称:hudson-tray-tracker,代码行数:17,代码来源:LoggingHelper.cs

示例14: HandleErrorResult

        internal static AggregateConsumingResult HandleErrorResult(this Task<AggregateConsumingResult> task,
                                                                   ILog log)
        {
            var result = task.Result;

            if (result is ConsumingFailureBase)
            {
                if (result is CorruptedMessageConsumingFailure)
                    log.Error("message content corruption detected");
                else if (result is UnresolvedMessageConsumingFailure)
                    log.Error("runtime type cannot be resolved");
                else if (result is UnsupportedMessageConsumingFailure)
                    log.Error("message type cannot be resolved");

                ((ConsumingFailureBase)result).WithErrors(_ => log.Error("consuming error",
                                                                         _.GetBaseException()));
            }

            return result;
        }
开发者ID:pichierri,项目名称:Carrot,代码行数:20,代码来源:ConsumerExtensions.cs

示例15: LogDirectoryContent

 // fail-safe
 public static void LogDirectoryContent(ILog logger, string directory)
 {
     try
     {
         DoLogDirectoryContent(logger, directory);
     }
     catch
     {
         if (logger != null)
             logger.Error("Failed to log directory content");
     }
 }
开发者ID:ViniciusConsultor,项目名称:hudson-tray-tracker,代码行数:13,代码来源:LoggingHelper.cs


注:本文中的ILog.Error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。