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


C# ILogger.Warn方法代码示例

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


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

示例1: GetCurrentUow

        private static IUnitOfWork GetCurrentUow(ILogger logger)
        {
            var unitOfWorkKey = CallContext.LogicalGetData(ContextKey) as string;
            if (unitOfWorkKey == null)
            {
                return null;
            }

            IUnitOfWork unitOfWork;
            if (!UnitOfWorkDictionary.TryGetValue(unitOfWorkKey, out unitOfWork))
            {
                logger.Warn("There is a unitOfWorkKey in CallContext but not in UnitOfWorkDictionary!");
                CallContext.FreeNamedDataSlot(ContextKey);
                return null;
            }

            if (unitOfWork.IsDisposed)
            {
                logger.Warn("There is a unitOfWorkKey in CallContext but the UOW was disposed!");
                UnitOfWorkDictionary.TryRemove(unitOfWorkKey, out unitOfWork);
                CallContext.FreeNamedDataSlot(ContextKey);
                return null;
            }

            return unitOfWork;
        }
开发者ID:Why-Not-Sky,项目名称:aspnetboilerplate,代码行数:26,代码来源:CallContextCurrentUnitOfWorkProvider.cs

示例2: GetFilteredFileSystemEntries

        /// <summary>
        /// Gets the filtered file system entries.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="searchPattern">The search pattern.</param>
        /// <param name="flattenFolderDepth">The flatten folder depth.</param>
        /// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param>
        /// <param name="args">The args.</param>
        /// <returns>Dictionary{System.StringFileSystemInfo}.</returns>
        /// <exception cref="System.ArgumentNullException">path</exception>
        public static Dictionary<string, FileSystemInfo> GetFilteredFileSystemEntries(string path, ILogger logger, string searchPattern = "*", int flattenFolderDepth = 0, bool resolveShortcuts = true, ItemResolveArgs args = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            var dict = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase);
            
            var entries = new DirectoryInfo(path).EnumerateFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly);

            foreach (var entry in entries)
            {
                var isDirectory = entry.Attributes.HasFlag(FileAttributes.Directory);

                if (resolveShortcuts && FileSystem.IsShortcut(entry.FullName))
                {
                    var newPath = FileSystem.ResolveShortcut(entry.FullName);

                    if (string.IsNullOrWhiteSpace(newPath))
                    {
                        //invalid shortcut - could be old or target could just be unavailable
                        logger.Warn("Encountered invalid shortcut: " + entry.FullName);
                        continue;
                    }

                    var data = FileSystem.GetFileSystemInfo(newPath);

                    if (data.Exists)
                    {
                        // add to our physical locations
                        if (args != null)
                        {
                            args.AddAdditionalLocation(newPath);
                        }

                        dict[data.FullName] = data;
                    }
                    else
                    {
                        logger.Warn("Cannot add unavailble/non-existent location {0}", data.FullName);
                    }
                }
                else if (flattenFolderDepth > 0 && isDirectory)
                {
                    foreach (var child in GetFilteredFileSystemEntries(entry.FullName, logger, flattenFolderDepth: flattenFolderDepth - 1, resolveShortcuts: resolveShortcuts))
                    {
                        dict[child.Key] = child.Value;
                    }
                }
                else
                {
                    dict[entry.FullName] = entry;
                }
            }

            return dict;
        }
开发者ID:snap608,项目名称:MediaBrowser,代码行数:69,代码来源:FileData.cs

示例3: AuthModule

        public AuthModule(ILogger<AuthModule> logger,
            IUserManager userManager,
            ITokenizer tokenizer)
            : base("auth")
        {
            Get["/setup"] = _ => !userManager.HasUsers();

            Post["/login"] = _ =>
            {
                var userData = this.Bind<UserDto>();

                // First login creates user
                if (!userManager.HasUsers())
                {
                    logger.Info("Creating user account {UserName}.", userData.UserName);
                    userManager.CreateUser(userData.UserName, userData.Password);
                }

                var user = userManager.GetUser(userData.UserName, userData.Password);

                if (user == null)
                {
                    logger.Warn("Invalid username/password: {UserName}.", userData.UserName);
                    return HttpStatusCode.Unauthorized;
                }

                var identity = new UserIdentity(user.UserName, user.Claims);
                var token = tokenizer.Tokenize(identity, Context);

                return new
                {
                    Token = token
                };
            };
        }
开发者ID:DNIDNL,项目名称:hadouken,代码行数:35,代码来源:AuthModule.cs

示例4: CreateJvmContext

        /// <summary>
        /// Create JVM.
        /// </summary>
        /// <param name="cfg">Configuration.</param>
        /// <param name="cbs">Callbacks.</param>
        /// <param name="log"></param>
        /// <returns>Context.</returns>
        internal static void CreateJvmContext(IgniteConfiguration cfg, UnmanagedCallbacks cbs, ILogger log)
        {
            lock (SyncRoot)
            {
                // 1. Warn about possible configuration inconsistency.
                JvmConfiguration jvmCfg = JvmConfig(cfg);

                if (!cfg.SuppressWarnings && _jvmCfg != null)
                {
                    if (!_jvmCfg.Equals(jvmCfg))
                    {
                        log.Warn("Attempting to start Ignite node with different Java " +
                            "configuration; current Java configuration will be ignored (consider " +
                            "starting node in separate process) [oldConfig=" + _jvmCfg +
                            ", newConfig=" + jvmCfg + ']');
                    }
                }

                // 2. Create unmanaged pointer.
                void* ctx = CreateJvm(cfg, cbs);

                cbs.SetContext(ctx);

                // 3. If this is the first JVM created, preserve it.
                if (_ctx == null)
                {
                    _ctx = ctx;
                    _jvmCfg = jvmCfg;
                }
            }
        }
开发者ID:kjniemi,项目名称:ignite,代码行数:38,代码来源:IgniteManager.cs

示例5: SetCurrentUow

        private static void SetCurrentUow(IUnitOfWork value, ILogger logger)
        {
            if (value == null)
            {
                ExitFromCurrentUowScope(logger);
                return;
            }

            var unitOfWorkKey = CallContext.LogicalGetData(ContextKey) as string;
            if (unitOfWorkKey != null)
            {
                IUnitOfWork outer;
                if (UnitOfWorkDictionary.TryGetValue(unitOfWorkKey, out outer))
                {
                    if (outer == value)
                    {
                        logger.Warn("Setting the same UOW to the CallContext, no need to set again!");
                        return;
                    }

                    value.Outer = outer;
                }
            }

            unitOfWorkKey = value.Id;
            if (!UnitOfWorkDictionary.TryAdd(unitOfWorkKey, value))
            {
                throw new AbpException("Can not set unit of work! UnitOfWorkDictionary.TryAdd returns false!");
            }

            logger.Debug("Entering a new UOW scope: " + unitOfWorkKey);
            CallContext.LogicalSetData(ContextKey, unitOfWorkKey);
        }
开发者ID:Why-Not-Sky,项目名称:aspnetboilerplate,代码行数:33,代码来源:CallContextCurrentUnitOfWorkProvider.cs

示例6: GetFilteredFileSystemEntries

        /// <summary>
        /// Gets the filtered file system entries.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="args">The args.</param>
        /// <param name="searchPattern">The search pattern.</param>
        /// <param name="flattenFolderDepth">The flatten folder depth.</param>
        /// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param>
        /// <returns>Dictionary{System.StringFileSystemInfo}.</returns>
        /// <exception cref="System.ArgumentNullException">path</exception>
        public static Dictionary<string, FileSystemInfo> GetFilteredFileSystemEntries(string path, ILogger logger, ItemResolveArgs args, string searchPattern = "*", int flattenFolderDepth = 0, bool resolveShortcuts = true)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            var entries = new DirectoryInfo(path).EnumerateFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly);

            if (!resolveShortcuts && flattenFolderDepth == 0)
            {
                return entries.ToDictionary(i => i.FullName, StringComparer.OrdinalIgnoreCase);
            }

            var dict = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase);

            foreach (var entry in entries)
            {
                var isDirectory = (entry.Attributes & FileAttributes.Directory) == FileAttributes.Directory;

                var fullName = entry.FullName;

                if (resolveShortcuts && FileSystem.IsShortcut(fullName))
                {
                    var newPath = FileSystem.ResolveShortcut(fullName);

                    if (string.IsNullOrWhiteSpace(newPath))
                    {
                        //invalid shortcut - could be old or target could just be unavailable
                        logger.Warn("Encountered invalid shortcut: " + fullName);
                        continue;
                    }

                    // Don't check if it exists here because that could return false for network shares.
                    var data = new DirectoryInfo(newPath);

                    // add to our physical locations
                    args.AddAdditionalLocation(newPath);

                    dict[newPath] = data;
                }
                else if (flattenFolderDepth > 0 && isDirectory)
                {
                    foreach (var child in GetFilteredFileSystemEntries(fullName, logger, args, flattenFolderDepth: flattenFolderDepth - 1, resolveShortcuts: resolveShortcuts))
                    {
                        dict[child.Key] = child.Value;
                    }
                }
                else
                {
                    dict[fullName] = entry;
                }
            }

            return dict;
        }
开发者ID:0sm0,项目名称:MediaBrowser,代码行数:71,代码来源:FileData.cs

示例7: GetCurrentUow

        /// <summary>
        /// 获取当前工作单元
        /// </summary>
        /// <param name="logger">日志</param>
        /// <returns></returns>
        private static IUnitOfWork GetCurrentUow(ILogger logger)
        {
            //获取当前工作单元key
            var unitOfWorkKey = CallContext.LogicalGetData(ContextKey) as string;
            if (unitOfWorkKey == null)
            {
                return null;
            }

            IUnitOfWork unitOfWork;
            if (!UnitOfWorkDictionary.TryGetValue(unitOfWorkKey, out unitOfWork))
            {
                //如果根据key获取不到当前工作单元,那么就从当前线程集合(CallContext)中释放key
                //logger.Warn("There is a unitOfWorkKey in CallContext but not in UnitOfWorkDictionary (on GetCurrentUow)! UnitOfWork key: " + unitOfWorkKey);
                CallContext.FreeNamedDataSlot(ContextKey);
                return null;
            }

            if (unitOfWork.IsDisposed)
            {
                //如果当前工作单元已经dispose,那么就从工作单元集合中移除,并将key从当前线程集合(CallContext)中释放
                logger.Warn("There is a unitOfWorkKey in CallContext but the UOW was disposed!");
                UnitOfWorkDictionary.TryRemove(unitOfWorkKey, out unitOfWork);
                CallContext.FreeNamedDataSlot(ContextKey);
                return null;
            }

            return unitOfWork;
        }
开发者ID:dafeifei0218,项目名称:aspnetboilerplate,代码行数:34,代码来源:CallContextCurrentUnitOfWorkProvider.cs

示例8: ResolveTypes

        /// <summary>
        /// Resolves the types for the given assembly
        /// </summary>
        /// <remarks>
        /// The resolver will first check its cache. If the types were previously resolved for the given assembly, then those are returned
        /// If nothing has been cached before, then the types are being resolved and added to the cache before being returned.
        /// </remarks>
        /// <param name="assembly">The assembly for which the types should be resolved</param>
        /// <param name="logger">The logger to use in case an exception should occur when resolving the types</param>
        /// <returns>List of types resolved for the given assembly</returns>
        public static Type[] ResolveTypes(Assembly assembly, ILogger logger)
        {
            // GetTypes potentially throws an exception. Defensive coding as per http://haacked.com/archive/2012/07/23/get-all-types-in-an-assembly.aspx

            Type[] allTypes;
            lock (typesByAssembly)
            {
                try
                {
                    if (!typesByAssembly.TryGetValue(assembly, out allTypes))
                    {
                        allTypes = assembly.GetTypes();
                        typesByAssembly.Add(assembly, allTypes);
                    }
                }
                catch (ReflectionTypeLoadException ex)
                {
                    allTypes = ex.Types.Where(t => t != null).ToArray();
                    typesByAssembly.Add(assembly, allTypes);

                    foreach (var exception in ex.LoaderExceptions)
                    {
                        logger.Warn(string.Format(Resources.DiscoverGetType, assembly.FullName), exception);
                    }
                }
            }

            return allTypes;
        }
开发者ID:rodius,项目名称:Glimpse,代码行数:39,代码来源:AssemblyTypesResolver.cs

示例9: Check

        public bool Check(AbstractConnection connection, ILogger logger) {
            if (CachedResults.ContainsKey(connection.Name)) {
                return CachedResults[connection.Name];
            }

            if (!new FileInfo(connection.Server).Exists) {
                logger.Warn("{0} not found.", connection.Server);

                var type = System.Type.GetType("System.Data.SqlServerCe.SqlCeEngine, System.Data.SqlServerCe", false, true);
                dynamic engine = System.Activator.CreateInstance(type, connection.GetConnectionString());
                engine.CreateDatabase();

                logger.Warn("Created {0} database file.", connection.Server);
            };

            return CheckConnection(connection);
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:17,代码来源:SqlCeConnectionChecker.cs

示例10: DefaultRetry

 public DefaultRetry(ILogger logger) : base(_numAttempts)
 {
     this
         .Chain(r => r.Started += (s, e) => logger.Debug("{Action}...", e.ActionName))
         .Chain(r => r.Success += (s, e) => logger.Debug("{Action} completed successfully in {Elapsed}.", e.ActionName, e.ElapsedTime))
         .Chain(r => r.TransientFailure += (s, e) => logger.Warn(e.Exception, "A transient failure occurred in action {Action}.", e.ActionName))
         .Chain(r => r.PermanentFailure += (s, e) => logger.Error(e.Exception, "A permanent failure occurred in action {Action}.", e.ActionName))
         .WithBackoff<DefaultRetry>(Backoff)
         ;
 }
开发者ID:fenix2222,项目名称:Nimbus,代码行数:10,代码来源:DefaultRetry.cs

示例11: JavascriptOperation

        public JavascriptOperation(
            string outKey, 
            string script, 
            Dictionary<string, Script> scripts, 
            IParameters parameters,
            ILogger logger)
            : base(string.Empty, outKey) {
            _script = script;
            _parameters = parameters;
            _addSelf = !parameters.Any();

            foreach (var pair in scripts) {
                logger.Debug("Running script {0}.", pair.Value.File);
                try
                {
                    var program = new JavaScriptParser().Parse(pair.Value.Content, new ParserOptions { Tolerant = true});
                    if (program.Errors != null && program.Errors.Count > 0) {
                        logger.Warn("Javascript Parse Failed. Script: {0}.", pair.Value.Name);
                        foreach (var error in program.Errors) {
                            logger.Warn(error.Description);
                        }
                    } else {
                        _scriptAppender.AppendLine(pair.Value.Content);
                    }
                }
                catch (Exception e) {
                    logger.Error("Javascript Parse Failed. Name: {0}. Script: {1}.", pair.Value.Name, pair.Value.Content);
                    logger.Error(e.Message);
                }
            }

            var externalScripts = _scriptAppender.ToString();
            if (externalScripts.Equals(string.Empty))
                return;

            logger.Debug("Loading scripts into Javascript engine...");
            logger.Debug(externalScripts.Replace("{","{{").Replace("}","}}"));
            _jint.Execute(externalScripts);

            Name = string.Format("Javascript({0}=>{1})", InKey, OutKey);
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:41,代码来源:JavascriptOperation.cs

示例12: LogResult

 internal static void LogResult(JobResult result, ILogger logger, string jobName) {
     if (result != null) {
         if (result.IsCancelled)
             logger.Warn(result.Error, "Job run \"{0}\" cancelled: {1}", jobName, result.Message);
         else if (!result.IsSuccess)
             logger.Error(result.Error, "Job run \"{0}\" failed: {1}", jobName, result.Message);
         else if (!String.IsNullOrEmpty(result.Message))
             logger.Info("Job run \"{0}\" succeeded: {1}", jobName, result.Message);
         else
             logger.Trace("Job run \"{0}\" succeeded.", jobName);
     } else {
         logger.Error("Null job run result for \"{0}\".", jobName);
     }
 }
开发者ID:yonglehou,项目名称:Foundatio,代码行数:14,代码来源:IJob.cs

示例13: WriteTestLog

 static void WriteTestLog(ILogger logger)
 {
     logger.Info("输出信息");
     logger.Debug("测试信息");
     logger.Warn("警告信息");
     try
     {
         int i = 1, j = 0;
         i = i / j;
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
 }
开发者ID:yimogit,项目名称:YimoFramework,代码行数:15,代码来源:TestController.cs

示例14: ProcessDeletion

		private bool ProcessDeletion(RemotingPackageManifestEntry action, ILogger logger)
		{
			var currentItem = Factory.GetDatabase(action.Database).GetItem(new ID(action.ItemId));

			if (currentItem == null)
			{
				logger.Error("Cannot delete {0} because it had already been deleted.".FormatWith(action.ItemPath));
				return false;
			}

			currentItem.Delete();
			logger.Warn("[D] {0} [remoting]".FormatWith(new SitecoreSourceItem(currentItem).DisplayIdentifier));

			return true;
		}
开发者ID:GlennHaworth,项目名称:Unicorn,代码行数:15,代码来源:DifferentialPackageReplayer.cs

示例15: ExitFromCurrentUowScope

        private static void ExitFromCurrentUowScope(ILogger logger)
        {
            var unitOfWorkKey = CallContext.LogicalGetData(ContextKey) as string;
            if (unitOfWorkKey == null)
            {
                logger.Warn("There is no current UOW to exit!");
                return;
            }

            IUnitOfWork unitOfWork;
            if (!UnitOfWorkDictionary.TryGetValue(unitOfWorkKey, out unitOfWork))
            {
                logger.Warn("There is a unitOfWorkKey in CallContext but not in UnitOfWorkDictionary");
                CallContext.FreeNamedDataSlot(ContextKey);
                return;
            }

            UnitOfWorkDictionary.TryRemove(unitOfWorkKey, out unitOfWork);
            if (unitOfWork.Outer == null)
            {
                CallContext.FreeNamedDataSlot(ContextKey);
                return;
            }

            // Restore outer UOW
            var outerUnitOfWorkKey = unitOfWork.Outer.Id;
            if (!UnitOfWorkDictionary.TryGetValue(outerUnitOfWorkKey, out unitOfWork))
            {
                // No Outer UOW
                logger.Warn("Outer UOW key could not found in UnitOfWorkDictionary!");
                CallContext.FreeNamedDataSlot(ContextKey);
                return;
            }

            CallContext.LogicalSetData(ContextKey, outerUnitOfWorkKey);
        }
开发者ID:lizhi5753186,项目名称:BDF,代码行数:36,代码来源:DefaultCurrentUnitOfWorkProvider.cs


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