标签: logfile

写入日志文件c#

我有一个代码,我从XML文件中读取一个我必须保存结果的路径,如果程序中出现错误并停止,请记下错误.

我的程序有这样的结构:

namespace RiskFactorListUpdater
{
    public static class Program
    {
       public static void Main(string[] args)
        {
            try
            {
                //get the data
                filename=.....;
                // blah blah blah


                // more code

              }catch(Exception e)
               {
                //write in log file
             }
Run Code Online (Sandbox Code Playgroud)

当我尝试读取文件名的路径时出现问题.我无法在捕获"部分"中阅读它.我是c#的新手.这样做有简单的方法吗?

提前致谢

c# xml logfile

0
推荐指数
1
解决办法
137
查看次数

计算IP地址的出现次数并将结果导出为CSV

我有CSV文件中的数据,如下所示:

src_ip,dst_ip,tran_src_ip,tran_dst_ip,srczone,src_country_code,dstzone,dst_country_code
75.76.77.78,23.24.25.26,192.168.1.100,192.168.1.18,"""""WAN""""",USA,"""""LOCAL""""",USA
75.76.77.78,23.24.25.26,,192.168.1.21,"""""WAN""""",USA,"""""LOCAL""""",USA
12.13.14.15,23.24.25.26,,192.168.1.21,"""""WAN""""",USA,"""""LOCAL""""",USA
23.24.25.26,23.24.25.26,192.168.1.100,192.168.1.18,"""""WAN""""",USA,"""""LOCAL""""",USA

我希望能够导入该文件,查看src_ip列中的值,并创建一个新的CSV文件,该文件将包含一个列,显示该src_ip地址在输入文件中显示的次数.

我发现这样的代码可以找到特定的模式,但是当我输入IP地址的正则表达式时,它对我来说效果不佳.我也不确定如何让它返回IP地址,以及该特定IP的出现次数.

$regex = '\b(\w+)=([^ ]+)'    
(Select-String -Path 'input_file.csv' -Pattern $regex -AllMatches |
    Select-Object -ExpandProperty Matches).Count
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望输出看起来像这样.

src_ip,Occurances
75.76.77.78,2
12.13.14.15,1
23.24.25.26,1

regex powershell parsing filtering logfile

0
推荐指数
1
解决办法
47
查看次数

连续读取bash脚本中日志文件的最后一行

我有一个日志文件,其中不断写入新行。

我想要一个 bash 脚本,它可以连续读取此日志文件的最后一行,以便我可以处理该行(例如,如果该行包含“错误”一词,则执行特定命令)。

我试过了:

while true
do
    if tail -n1 -f file.log | grep -q ERROR
    then
        echo "$(date) : ERROR detected"
    fi
done
Run Code Online (Sandbox Code Playgroud)

但这是垃圾邮件:

sun 21 mar 2021 18:32:41 CET : ERROR detected
sun 21 mar 2021 18:32:41 CET : ERROR detected
sun 21 mar 2021 18:32:41 CET : ERROR detected
sun 21 mar 2021 18:32:41 CET : ERROR detected
sun 21 mar 2021 18:32:41 CET : ERROR detected
sun 21 mar 2021 18:32:41 CET : ERROR detected …
Run Code Online (Sandbox Code Playgroud)

bash shell file logfile

0
推荐指数
1
解决办法
52
查看次数

该日志文件是什么格式?有没有办法转换它?

这可能是一个毫无意义的问题,但由于我不知道要搜索什么以及如何搜索,所以我决定向公众提出这个问题。如果您认为这个问题需要改进或需要更多信息,请发表评论。我会尽力尽快回复并编辑。

我有一个简单的 Go 程序,它使用名为Zerolog 的三十方日志库并打印日志。

package main

import (
    "os"
    "time"

    "github.com/rs/zerolog"
    "github.com/rs/zerolog/log"
)

func init() {
    zerolog.SetGlobalLevel(zerolog.DebugLevel)
    zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
    log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339Nano})
}

func main() {
    log.Debug().Msg("This if debugging message")
    log.Info().Msg("This is information message")
}

Run Code Online (Sandbox Code Playgroud)

如果您只是使用 运行该程序$ go run main.go,它会打印出以下结果。

2021-06-23T12:45:29.409Z DBG This if debugging message
2021-06-23T12:45:29.41Z INF This is information message
Run Code Online (Sandbox Code Playgroud)

但是,如果我用来nohup运行这个程序$ nohup go run main.go &,那么它会创建一个名为 的输出文件nohup.out并写入不同的日志格式。这是为什么?

[90m2021-06-23T12:59:37.755Z[0m [33mDBG[0m This if debugging message
[90m2021-06-23T12:59:37.756Z[0m …
Run Code Online (Sandbox Code Playgroud)

format go nohup logfile

0
推荐指数
1
解决办法
1365
查看次数

标签 统计

logfile ×4

bash ×1

c# ×1

file ×1

filtering ×1

format ×1

go ×1

nohup ×1

parsing ×1

powershell ×1

regex ×1

shell ×1

xml ×1