如何通过NDC过滤?(How to filter by NDC?)
在log4net中,我想按NDC的值过滤日志消息,如下所示:
<filter type="log4net.Filter.PropertyFilter"> <Key value="NDC" /> <stringToMatch value="MyContext" /> </filter>
不知何故上面的过滤器没有像我预期的那样工作。
如何为我的appender配置只匹配某个NDC的过滤器?
In log4net I want to filter log messages by the value of the NDC like this:
<filter type="log4net.Filter.PropertyFilter"> <Key value="NDC" /> <stringToMatch value="MyContext" /> </filter>
Somehow the above filter is not working like I expected.
How do I have to configure a filter for my appender that will only match a certain NDC?
原文:https://stackoverflow.com/questions/1674411
最满意答案
您可以使用
sed
的以下技巧:首先用制表符替换所有空格,然后替换一个空格。 这是一个例子:echo "a b c d" | sed 's/ /:/g;s/:/ /'
第一个sed命令
s/ /:/g
用冒号替换全局(因此g)所有空格,第二个用空格替换第一个冒号。 这将字符串abcd
转换为ab:c:d
。You could use the following trick with
sed
: First replace all blanks with tabs, then replace exactly one. Here's an example for illustration:echo "a b c d" | sed 's/ /:/g;s/:/ /'
The first sed command
s/ /:/g
replaces globally (hence the g) all blanks with colons, and the second replaces the first colon with a blank. This turns the stringa b c d
intoa b:c:d
.
相关问答
更多-
打开窗口 - >菜单栏中的首选项。 从树形菜单中选择Text Editors 。 取消选中Insert spaces for tabs 。 之后,从上下文菜单运行Format菜单并保存文件: Open Window->Preferences from menu bar. Select Text Editors from tree menu. Uncheck Insert spaces for tabs. After that, run Format menu from context menu and sa ...
-
您可以使用sed的以下技巧:首先用制表符替换所有空格,然后替换一个空格。 这是一个例子: echo "a b c d" | sed 's/ /:/g;s/:/ /' 第一个sed命令s/ /:/g用冒号替换全局(因此g)所有空格,第二个用空格替换第一个冒号。 这将字符串abcd转换为ab:c:d 。 You could use the following trick with sed: First replace all blanks with tabs, then replace exactly one ...
-
您是否考虑过使用内置的slugify过滤器? 你的第二个表达式的问题是你正在使用正面的lookbehind( ?<= )。 来自regular-expressions.info : “零宽度正向后观。如果前瞻中的图案可以匹配在该位置结束(即该位置的左侧),则匹配位置。 以下可能是您尝试做的事情: re.sub('[,.?!\t\n ]+', '-', s) 这是用一个破折号替换任何字符序列,.?!\t\n 。 Have you considered using the built in slugify f ...
-
\s类匹配空格字符。 从而: stringValue = stringValue.replaceAll("\\s+", " "); 要在每个问题中替换空格转义字符串,可以按如下方式组合四个正则表达式: "(?:\\\\[nrt])+| +" The \s class matches whitespace characters. Thus: stringValue = stringValue.replaceAll("\\s+", " "); To substitute whitespace escape ...
-
Linux或许多Unix系统上最简单的解决方案是使用expand命令。 如果使用Vi或Vim编辑文件,可以将以下内容添加到.vimrc文件中,以确保在编辑文件时始终将选项卡扩展为空格: set expandtab 有关Vim和选项卡的更多信息,请参阅将选项卡转换为空格 。 awk '{s="";i=1;while(substr($0,i++,1)=="\t")s=s " ";sub(/^\t*/,s)}1'
-
用单个空格替换一个或多个空格和/或制表符的每个字符串(replacing each string of one or more spaces and/or tabs by a single space)[2022-11-12]
问题是getchar()在输入时回显输入,通过回显您想要压缩的空格和制表符来使您感到困惑。 使用非回显getch()尝试此操作。 我没有使用EOF结束,但是回来 ,按照你的意愿进行实验。 #include#include int main(void) { int c, lastc = -1; while ((c = getch()) != '\r') { if (c != ' ' && c != '\t'){ ... -
由于您在标签前有空格,因此可以使用此sed: sed $'s/ *\t/ /g' test A B A B A B A B 这也将在tab之前用4个空格替换0或更多空格。 Since you have spaces before tabs you can use this sed: sed $'s/ *\t/ /g' test A B A B A B A B This will also replace 0 or more spaces b ...
-
在Python中,您可以捕获字符串的不同部分,并使用lambda表达式操作re.sub的捕获组内容: import re s = """ s_Tmp = 'ERROR: month "' | s_Month | '" not valid - ABORT' | CHAR(13) | CHAR(10) ;""" res = re.sub(r"^(\s*)(.*)", lambda x: "{}{}".format(x.group(1), x.gro ...
-
如另一个问题所述,查看readSelectionFromPasteboard:type: 覆盖它并更换粘贴板。 例如: - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard type:(NSString *)type { id data = [pboard dataForType:type]; NSDictionary *dictionary = nil; NSMutableAttributedString *text ...
-
打开要为其设置首选项的格式的文件,然后执行以下操作: 单击Sublime Text 2 - > Preferences - > Settings - More - > Syntax Specific - User 这将打开一个文件,用于您正在编辑的文件格式的首选项; 例如,如果您正在编辑.c文件,您将设置C语言文件的首选项。 在上导航后,将其添加到Sublime Text打开的文件中: { "tab_size":
, "translate_tabs_to_spaces" ...