我在我的项目的App_code文件夹中编写了一个名为ArchivedFilesWrapper的类,但是当我在另一个文件夹中使用此类时,我得到错误:
找不到类型或命名空间名称'ArchivedFilesWrapper'(您是否缺少using指令或程序集引用?)
我认为每个页面都应该能够找到包含在同一个项目中的类,但我想情况并非如此.有人可以告诉我我需要使用的声明吗?
这是我班上的一个片段:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EMCWebAdmin.App_Code
{
public class ArchivedFilesWrapper
{
Run Code Online (Sandbox Code Playgroud) 我试图了解将 basicConfig 与多个处理程序一起使用时日志记录模块的行为。
我的目标是对系统日志消息设置警告级别,对日志文件设置调试级别。
这是我的设置:
import logging
import logging.handlers
import os
from datetime import datetime
log_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
f_handler = logging.FileHandler(f'{os.path.expanduser("~")}/logs/test_{datetime.now().strftime("%Y%m%d%H%M%S")}.log')
s_handler = logging.handlers.SysLogHandler(address='/dev/log')
f_handler.setLevel(logging.DEBUG)
s_handler.setLevel(logging.WARN)
f_handler.setFormatter(log_format)
s_handler.setFormatter(log_format)
logging.basicConfig(handlers=[f_handler, s_handler])
print (logging.getLogger().getEffectiveLevel())
logging.warning('This is a warning')
logging.error('This is an error')
logging.info('This is an info')
logging.debug('This is debug')
Run Code Online (Sandbox Code Playgroud)
这不起作用 - 我的日志文件仅包含警告和错误消息,而不是预期的调试和信息消息。
如果我将此行更改为:
logging.basicConfig(handlers=[f_handler, s_handler], level=logging.DEBUG)
Run Code Online (Sandbox Code Playgroud)
那么这似乎确实有效,即该文件包含所有消息,而系统日志仅包含错误和警告消息。
我不明白为什么原始代码不起作用,因为我专门在文件处理程序上设置了级别。