docker - 无法确定 Windows 容器注册表编辑访问权限
问题描述
迁移到在 mcr.microsoft.com/dotnet/core/aspnet:3.1 上运行的 windows 容器访问注册表时出现问题。
具体来说,我尝试运行该应用程序并拨打电话,我得到以下信息:
Caught exception while emitting to sink Serilog.Core.Sinks.RestrictedSink: System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security.
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
at System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate)
at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID)
at Serilog.Sinks.EventLog.EventLogSink.Emit(LogEvent logEvent)
at Serilog.Core.Sinks.RestrictedSink.Emit(LogEvent logEvent)
at Serilog.Core.Sinks.SafeAggregateSink.Emit(LogEvent logEvent)
最初我认为这是缺少源的问题,所以我尝试通过以下方式添加现有应用程序期望在服务器上的一些键,
RUN cmd.exe /k REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\blahblah.Api"
然而,这似乎并没有解决这个问题,我有一个地狱般的时间来确定如何给予适当的权限,人们期望req。从最初的消息。
我知道应用程序正在运行到某个点,因为我已经解决了远程数据库连接错误和 SSL 请求详细信息以达到这一点。
解决方案
您可以使用的一个简单技巧是将您的日志写入一个名为的源,该源Application
保证存在于机器中,这是所有常见 Windows 日志所在的位置。这样您就不必创建新源(并且不需要特殊权限)。例如:
Log.Logger = new LoggerConfiguration()
.WriteTo.EventLog(source: "Application")
.CreateLogger();
或者,如果您的应用程序在 Docker 容器中以管理员权限运行,您可以通过打开 来告诉 Serilog 为您创建事件日志源manageEventSource
。例如
Log.Logger = new LoggerConfiguration()
.WriteTo.EventLog(/* ... */, manageEventSource: true)
.CreateLogger();
另一种方法是使用eventcreate
为您创建事件源(需要以管理员权限运行)。
eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO "blahblah.Api" /D "blahblah.Api"
当然,您需要确保告诉 Serilog 使用您创建的事件日志源:
Log.Logger = new LoggerConfiguration()
.WriteTo.EventLog(source: "blahblah.Api")
.CreateLogger();
也就是说,我同意Mason 的上述评论,即在 Docker 环境中,您不应该真正写入 EventLog。有更好的水槽可用。
推荐阅读
- r - 如何跨多个列获得最常见的组合
- validation - Laravel 6.x 中的路由参数验证
- python - 初学者:Python 找不到“pyodbc”包?
- c - Win32 上的异步串行 I/O -- 如何创建警报事件
- php - 在接受 cookie 同意之前替换所有 youtube iframe
- java - 我需要从 List 的字符串中迭代数据,并从以下 JSON 的“MemberOf”参数中添加到另一个列表字符串中
- java - 检查月、日或年是否在两个日期的范围内
- scala - 如何从 sbt 的动态任务中检测当前项目是否是根项目?
- node.js - node.js + express ,分隔文件和中间件中的路由器仅在某些路由之前?
- c# - 带有 Caliburn Micro wpf 的多个模板 TreeView