本地化 Windows 服务
我找了很久,但这个话题似乎很特别。我什么也没想出来。也许这里的专家可以帮助我。
我运行一个 Windows 服务来访问一些数据库并进行一些计算。如果出现故障,则会在日志文件中记录一个条目。 我的愿望是将这些条目本地化。 到目前为止,除了这个 Windows 服务之外,这对每个项目都运行良好。
我使用资源管理器和本地化资源文件。 在运行时,CultureInfo 会通过以下方式更改:
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
其中 language 是从配置文件中读取的值。 更改在下一行中得到确认:
LogService.WriteEntry(CultureInfo.CurrentUICulture.Name, EventLogEntryType.Information);
这有效并返回正确的 CultureInfo。 资源文件的命名正确,但仍然无法访问本地化文件(在这种情况下为“de”),并且使用默认(英语)文件。 我将资源文件添加到安装项目中的项目输出中。
编辑: 在其他项目中,以下方法工作正常,但不适用于 Windows 服务:
ResourceManager locRM = new ResourceManager("WindowsService.ResWindowsService", Assembly.GetExecutingAssembly());
Windows 服务似乎无法找到附属程序集,然后退回到似乎位于 Windows 服务 exe 文件内的中性资源文件。 有谁知道如何让 Windows 服务找到卫星程序集。
编辑 2:解决方案
一位亲爱的同事提供了帮助。 我强烈命名了卫星程序集并将其注册到 GAC 中。这就是解决方案。现在 Windows 服务可以访问它。 详细步骤: 在安装项目的文件系统编辑器中:添加特殊文件夹 ->全局程序集缓存文件夹。 添加文件->我这里添加了资源文件 然后在项目属性下 ->签名标记“签署程序集”并创建新的密钥文件。
就是这样。
谢谢, 尼尔斯
I have been searching for a long time but the topic seems to be quite special. I didn't come up with anything. Maybe the specialists arounf here can help me.
I run a Windows Service which accesses some databases and does some calculation. If something fails, then that will result in an entry in a log file.
My wish is to lacalize these entries.
This worked fine with every project so far except for this Windows Service.
I use the resource manager and localized resources files.
During runtime the CultureInfo is changed by:
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
where language is a value read from the config file.
The changes are veryfied at the next line:
LogService.WriteEntry(CultureInfo.CurrentUICulture.Name, EventLogEntryType.Information);
This works and returns the correct CultureInfo.
The resources files are named correctly but still, the localized file (in that case "de") can't be accessed and the default (english) file is used.
I added the resource files to the project output in the setup project.
Edit:
In other Projects, the following worked fine, but not for the Windows Service:
ResourceManager locRM = new ResourceManager("WindowsService.ResWindowsService", Assembly.GetExecutingAssembly());
It seems the Windows Service just can't find the satellite assembly and then falls back to the neutral resource file which seems to be within the Windows Service exe file.
Has anyone an idea how i can get the Windows Service to find the satellite assembly.
Edit 2: THE SOLUTION
A dear colleague helped.
I strongly named the satellite assembly and registered it in the GAC. That was the solution. Now the Windows Service can access it.
Detailed steps:
In the setup project's file system editor: Add special folder -> Global assembly cache folder.
Add file -> I added the resource file here
Then under Project Properties -> Signing mark "Sign the Assembly" and create a new key file.
That's it.
Thanks,
Nils
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论