在Serilog中,您可以轻松启用滚动日志文件:
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.chrome.options import Options
from datetime import datetime
myProxy = {
"http" : "http://10.120.118.49:8080",
"https" : "https://10.120.118.49:8080"
}
headers={'User-agent' : 'Mozilla/5.0'}
startTime=datetime.now()
options = Options()
proxy = Proxy()
proxy.proxyType = ProxyType.MANUAL
proxy.autodetect = False
proxy.httpProxy = proxy.sslProxy = proxy.socksProxy = "http://10.120.118.49:8080"
options.Proxy = proxy
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.add_argument("test-type");
options.add_argument("start-maximized");
options.add_argument("--window-size=1920,1080");
options.add_argument("--enable-precise-memory-info");
options.add_argument("--disable-popup-blocking");
options.add_argument("--disable-default-apps");
options.add_argument("test-type=browser");
options.add_argument("--no-sandbox");
options.add_argument("--user-data-dir=C:/Users/C71220/AppData/Local/Google/Chrome/hello");
driver = webdriver.Chrome(r"C:/Users/C71220/chromedriver.exe", options=options)
url='https://www.delhaize.be/nl-be/shop/Dranken-en-alcohol/Frisdrank/c/v2DRISOF?q=:relevance:manufacturerNameFacet:Fanta:manufacturerNameFacet:Coca-Cola:manufacturerNameFacet:Schweppes:manufacturerNameFacet:Fuze%20Tea:manufacturerNameFacet:Monster:manufacturerNameFacet:Sprite:manufacturerNameFacet:Aquarius:manufacturerNameFacet:Finley:manufacturerNameFacet:Honest&sort=relevance&pageNumber=0'
driver.get(url)
product_name="""/html/body/main/div[1]/div[3]/ul/li[1]/div/div/div[2]/div[1]/header/a/div/p[2]"""
product= driver.find_element_by_xpath(product_name)
print(product.text)
driver.close()
endtime=f'''Execution Time:datetime.now() - startTime'''
这将每天创建以下格式的新日志文件:
Log.Logger = new LoggerConfiguration()
.WriteTo.File("log-.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
log-20200214.txt
log-20200215.txt
我的问题:是否可以自定义日期在文件名中的位置以及自定义日期的格式?
例如我希望文件名看起来像这样:
log-20200216.txt
2020-02-14-log.txt
2020-02-15-log.txt
我希望将2020-02-16-log.txt
替换为"log-.txt"
可以,但是不能。
答案 0 :(得分:1)
Serilog.Sinks.File接收器当前不支持此功能。如果您确实需要此功能,则可以尝试send a pull-request或派生存储库并使用自己的自定义实现。
您可能感兴趣的链接: