如何将docker和Nlog配置为具有tcp日志记录?我使用log4view和udp日志记录在我的机器上运行平稳,配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Debug"
internalLogFile="c:\Temp\internal-nlog.txt">
<targets>
<target xsi:type="File" name="file" fileName="c:\Temp\xRayServices-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<target name="udp" xsi:type="Network" address="udp4://localhost:9999"
layout="${log4jxmlevent}" newline="True" />
</targets>
<target name="tcp" xsi:type="Network" address="tcp4://localhost:9995"
layout="${log4jxmlevent}" newline="True" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file,udp,tcp" />
</rules>
</nlog>
我还使用上述配置中的文件目标将docker容器中的日志写入文件,然后在启动docker映像时将docker目录映射到我的系统目录,如下所示(简化为只保留要点):
docker run --rm --name myName -p 9995:9995 -p 9999:9999/udp --network myLocalNet --mount "type=bind,source=C:\Temp,destination=C:\Temp" myImage
这样就可以使用txt文件日志了。我真的很想使用Log4view。
在我的例子中,出于安全原因,我需要使用--网络myLocalNet。
是否可以在使用--网络myLocalNet时进行tcp (或udp )日志记录.
注意,在上面的命令中,我尝试映射端口9999,但是我没有接收udp日志(我猜是因为--网络myLocalNet)。在日志记录配置和docker配置中,由于日志是从容器发送到我的计算机,所以我需要使我的计算机IP入口在对接器容器中可见。
UPDATE:在@LinPy的反馈之后,我添加了/udp标志,我还映射了一个seaparate端口并更新了日志配置。配置在本地为tcp和udp工作,但仍然不能从容器中运行。
我还添加了公开9999/udp,并将9995公开到docker文件中。
发布于 2019-09-24 23:18:24
尝试同时公开TCP
和UDP
docker run --rm --name myName -p 9999:9999/udp -p 9999:9999 --network myLocalNet --mount "type=bind,source=C:\Temp,destination=C:\Temp" myImage
发布于 2020-02-12 02:45:54
您不必打开任何带有-p参数的端口来执行端口映射,因为它不是传入的连接,NLog不会打开端口。NLog连接到您定义的端点。
因此,要使其工作,只需将localhost:9999
更改为<your-ip-host>:9999
即可。
https://stackoverflow.com/questions/58092984
复制