我正在从C++编码切换到C#.我需要用C#中类似的东西替换我的C++错误日志/报告宏系统.
在我的C++源代码中,我可以写
LOGERR("有些错误"); 或LOGERR("输入%s和%d出错",stringvar,intvar);
宏和支持库代码然后将(可能是varargs)格式化的消息与源文件,源代码行,用户名和时间一起传递到数据库中.相同的数据也被填充到数据结构中,以便稍后向用户报告.
有没有人有C#代码片段或指向执行此基本错误报告/日志记录的示例的指针?
编辑: 当我问这个问题时,我对.NET很陌生,并且不知道System.Diagnostics.Trace.System.Diagnostics.Trace是我当时需要的.从那以后,我在日志记录要求更大,更复杂的项目中使用了log4net.只需编辑500行XML配置文件,log4net即可完成您需要的所有内容:)
我有一些业余爱好C编程项目,我想开始.我正在寻找一个拥有自由许可证的开源库(我想要信用,但几乎任何人都可以使用).库需要比C标准库和一些可移植的线程原语更好的字符串.
我正在编写一个C#.NET 2.0 .dll,它是一个更大的应用程序的插件.我的模块的visual studio项目有一个app.config文件,该文件被复制到MyProj.dll旁边的MyProj.dll.config.
计划是在部署.dll之后编辑MyProj.dll.config.我试图从修改后的本地文件中读取我的设置.我试图拉出LocalFilesSettingsObject并将其应用程序名称更改为我的.dll,如下所示:
Properties.Settings config = Properties.Settings.Default;
SettingsContext context = config.Context;
SettingsPropertyCollection properties = config.Properties;
SettingsProviderCollection providers = config.Providers;
SettingsProvider configFile = Properties.Settings.Default.Providers["LocalFileSettingsProvider"];
configFile.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name;
config.Initialize(context, properties, providers);
config.Reload();
Run Code Online (Sandbox Code Playgroud)
那不行.我正在努力绕过整个.NET设置混乱.我想要一个配方来完成这项任务.我还想要一个关于如何在.NET 2.0中使用设置的清晰解释(带有示例)的链接
我想学习如何使用NUnit.我通过阅读然后玩真实代码来学习最好.我在哪里可以找到一个以示例性方式使用NUnit的小型简单C#项目?
I am writing a system in C# .net (2.0). It has a pluggable module sort of architecture. Assemblies can be added to the system without rebuilding the base modules. To make a connection to the new module, I wish to attempt to call a static method in some other module by name. I do not want the called module to be referenced in any manner at build time.
Back when I was writing unmanaged code starting from the path to …
我正在访问我的程序集的配置,如下所示:
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config";
Configuration conf = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
AppSettingsSection appSettings = conf.AppSettings;
Run Code Online (Sandbox Code Playgroud)
我的.config文件包含这样的部分
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="CsDll.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="CsDll.Properties.Settings.SabreCAD" connectionString="A Connection string." />
<add name="CsDll.Properties.Settings.StpParts" connectionString="Another connection string" />
</connectionStrings>
<applicationSettings>
<CsDll.Properties.Settings>
<setting name="StpInsertSearchPath" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>A string</string>
<string>Another string in the collection</string>
Run Code Online (Sandbox Code Playgroud)
如果我编辑.config文件,我可以成功读取连接字符串,包括更改.所以,我知道我已连接到正确的文件.但我无法在appSettings对象中找到该字符串集合.它不在.Settings KeyValueConfigurationCollection中.我在哪里可以找到我的字符串集合?
我有一个图表,其中我有两个节点(0和6),我必须尽可能削减最小边缘,以便它们不连接.例如,在此图中
作为节点0和6,我必须切割的最小边是2-7和3-7.我的想法是找到两者之间使用bfs的最短路径,我找到一个(0-2-7-6),但后来我不知道如何找到另一个(0-3-7-6).即便如此,我也不知道如何选择切边.
如果有人能就这件事给我一些指示,那就太好了.
c# ×4
.net-2.0 ×2
.net ×1
algorithm ×1
appsettings ×1
apr ×1
c ×1
c#-2.0 ×1
glib ×1
java ×1
nunit ×1
open-source ×1
settings ×1
unit-testing ×1