Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to force Docker.DotNet (NET CORE) read last log records #553

Open
Alex-1357 opened this issue Jan 29, 2022 · 0 comments
Open

How to force Docker.DotNet (NET CORE) read last log records #553

Alex-1357 opened this issue Jan 29, 2022 · 0 comments

Comments

@Alex-1357
Copy link

I try to use this package with my project, but failed. Unfortunately many function working in my project with troubles. This is my code to read docker container logs.

 Function ReadContainerLog(DockerHub As DockerClient, ContainerID As String, Readlog As Action(Of String), LogsCts As CancellationToken) As Task
     Dim ContainerLogsTask As Task = DockerHub.Containers.GetContainerLogsAsync(
                   ContainerID,
                   New ContainerLogsParameters With {
                     .ShowStderr = True,
                     .ShowStdout = True,
                     .Timestamps = True,
                     .Follow = True
                    },
                   LogsCts,
                   New Progress(Of String)(Readlog)
                   )
     Return ContainerLogsTask
 End Function

 Module Program
     Sub Main(args As String())

     Dim LogCtsSrc As New CancellationTokenSource()
     Dim ContainerLogs As New List(Of String)
     Public Sub ReadLog(Line As String)
         If LogCtsSrc.IsCancellationRequested Then Exit Sub
         ContainerLogs.Add(Line)
     End Sub
     ...
     ReadContainerLog(DockerHub, ContainerId, AddressOf ReadLog, LogCtsSrc.Token)
     '
     Console.ReadKey()
     Task.Delay(TimeSpan.FromSeconds(5))
     LogCtsSrc.Cancel()
     '
     Dim j As Integer = 0
     ContainerLogs.ForEach(Sub(X)
                                j = j + 1
                                Console.WriteLine(j.ToString & ": " & X)
                           End Sub)

Unfortunately, last records don't read from docker socket and don't pass to my software. Please see to screenshot.

docker_01292022_203311-1

What I doing wrong and how to force pass last log records from buffer to my software?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant