Container experience of traditional. NET 4.x applications

In Windows Container, how to check the abnormal information of the system without logging?

1 about Windows event log

In the past, when deploying ASP.NET applications based on IIS, if the specified log is not written, we often use the Window event log to view some error messages.

Although the readability and ease of use of the event log are not good enough, it can still help us see some problems. No, I deployed the Service project of our team's old system (large monomer ASP.NET MVC project) in the company's test environment for POC pilot verification. After running several interfaces, I found that the system directly returned 503 error. For the first time I ran ASP.NET MVC application on Windows Container, I was a little confused. There was not enough information to view IIS Log inside the container. All I could think of was to see the event log.

2. View the event log under docker

Step 1. First enter the ASP.NET MVC container instance:

>docker exec -it <container_name> powershell

Step 2. Get the latest 20 event logs and get the Index of the corresponding log:

>Get-Eventlog -newest 20 application
Index Time          EntryType   Source                 InstanceID Message
      96 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      95 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      94 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      93 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      92 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      91 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      90 Jul 22 15:34  Error       Application Error            1000 Faulting application name: w3wp.exe, version: 1...
      89 Jul 22 15:34  Error       .NET Runtime                 1026 Application: w3wp.exe...
      88 Jul 22 15:34  Error       ASP.NET 4.0.30319.0    3221226797 An unhandled exception occurred and the process...
      87 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      86 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      85 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      84 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      83 Jul 22 15:34  Information Windows Error Rep...         1001 Fault bucket , type 0...
      ......

Step3. Find the wrong index es and view the error log through the following command:

>(Get-Eventlog -index 89 application).message
An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/1/ROOT

Process ID: 7664

Exception: System.TypeInitializationException

Message: The type initializer for 'NewLife.Log.XTrace' threw an exception.

StackTrace:    at NewLife.Log.XTrace.WriteException(Exception ex)
   at NewLife.Threading.ThreadPoolX.<>c__DisplayClass2_0.<QueueUserWorkItem>b__0(Object s)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

InnerException: System.UnauthorizedAccessException

Message: Access to the path 'C:\inetpub\wwwroot\Config' is denied.

StackTrace:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost
)
   at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
   at System.IO.PathHelper.EnsureDirectory(String path, Boolean isfile)
   ......

It can be seen from the error log that the Config directory cannot be accessed. After investigation, it is found that there is a manually copied Config directory under the IIS directory of the existing system (the correct approach should always output it to the release directory as part of the solution), so it is copied to the container directory, re mirrored and run. The problem is solved, Smooth operation!

3 Summary

This article introduces how to check the exception log information of ASP.NET application through event log in Windows Container. Although the article is very short, I hope it is useful to you.

We are still exploring the container migration of traditional. NET 4.x applications. I believe that with the deepening of exploration and practice, I will share more relevant content.

 

 

Author: Zhou Xulong

source: https://edisonchou.cnblogs.com

The copyright of this article belongs to the author and the blog park. Reprint is welcome, but this statement must be retained without the consent of the author, and the original link must be given in an obvious position on the article page.

Keywords: Docker .NET

Added by border20 on Sun, 28 Nov 2021 09:59:13 +0200