首页 \ 问答 \ 如何在.net中实现跟踪(How to implement tracing in .net)

如何在.net中实现跟踪(How to implement tracing in .net)

我正在自己实施追踪机制。 现在我想知道的是实现这种机制的最佳方式是什么(我的意思是架构)。 首先,我想创建一个这样的班级:

class Tracer {
    public void NewEventRegistered(etc) {...} //this is the method I use to send this class the events I want to register

    event newEventRegistered(..) //this is the event the user is going to use to catch all the events in the application that have been sent to NewEventRegistered method.
}

但后来我看到有一个TraceListener类让我实现Write和WriteLine方法。 最大的缺点是这两种方法只允许字符串作为参数,我希望能够发送比字符串更多的信息。 我该怎么办? 也许我的第一个ideia是最好的?

编辑:我知道有很多像PostSharp这样的追踪机制,所以我只是为了学习的目的而这样做!


I am implementing a tracing mechanism myself. Now what I'd like to know is what is the best way to implement this mechanism(I mean, the architecture). First I thought of creating a class like this:

class Tracer {
    public void NewEventRegistered(etc) {...} //this is the method I use to send this class the events I want to register

    event newEventRegistered(..) //this is the event the user is going to use to catch all the events in the application that have been sent to NewEventRegistered method.
}

But then I saw there is an TraceListener class that let's me implement Write and WriteLine methods. The big drawback is that both those methods allow only strings as arguments, and I'd want to be able to send a lot more info than strings. What should I do? Maybe my first ideia is the best?

edit: I do know there are a lot of tracing mechanisms like PostSharp and so, I'm just doing this for learning purposes!


原文:https://stackoverflow.com/questions/1242341
更新时间:2024-04-24 21:04

最满意答案

通过该项目,您可以获取所有类路径条目。 我经历了并排除了常春藤条目。 然后我用正确的类路径和属性文件重新添加它们。 现在,路径不包括$ {ivyproject_loc}和$ {project_loc}。

代码如下:

protected void changeIvyClasspath(IProject project, IProgressMonitor monitor) throws CoreException {

    if(project.hasNature(JavaCore.NATURE_ID)){
        IJavaProject jproject = JavaCore.create(project);
        List<IClasspathEntry> iClasspathEntryList = new ArrayList<IClasspathEntry>();

        IClasspathEntry[] entries = jproject.getRawClasspath();
        for (IClasspathEntry entry : entries) {
            //exclude ivy.xml entries
            if (!entry.getPath().toString().contains("ivy.xml")) {
                iClasspathEntryList.add(entry);
            } 
        }

        //Add the ivy entries with the correct class path
        addIvyToClasspath(new String[] { "compile", "runtime" }, true, iClasspathEntryList, project, jproject, monitor);
        addIvyToClasspath(new String[] { "provided", "test" }, false, iClasspathEntryList, project, jproject, monitor);

        entries = iClasspathEntryList.toArray(new IClasspathEntry[iClasspathEntryList.size()]);

        jproject.setRawClasspath(entries, jproject.getOutputLocation(), null);
    }
}

With the project, you can get all the class path entries. I went through and excludes the ivy entries. Then I re-added them with the correct class path and property files. Now, the paths do not include ${ivyproject_loc} and ${project_loc}.

Here is the code:

protected void changeIvyClasspath(IProject project, IProgressMonitor monitor) throws CoreException {

    if(project.hasNature(JavaCore.NATURE_ID)){
        IJavaProject jproject = JavaCore.create(project);
        List<IClasspathEntry> iClasspathEntryList = new ArrayList<IClasspathEntry>();

        IClasspathEntry[] entries = jproject.getRawClasspath();
        for (IClasspathEntry entry : entries) {
            //exclude ivy.xml entries
            if (!entry.getPath().toString().contains("ivy.xml")) {
                iClasspathEntryList.add(entry);
            } 
        }

        //Add the ivy entries with the correct class path
        addIvyToClasspath(new String[] { "compile", "runtime" }, true, iClasspathEntryList, project, jproject, monitor);
        addIvyToClasspath(new String[] { "provided", "test" }, false, iClasspathEntryList, project, jproject, monitor);

        entries = iClasspathEntryList.toArray(new IClasspathEntry[iClasspathEntryList.size()]);

        jproject.setRawClasspath(entries, jproject.getOutputLocation(), null);
    }
}

相关问答

更多
  • 这是我发现的: 是更新和更喜欢的方式。 可能会或可能不会被弃用。 不会设置我的常春藤设置,直到调用 ,而在任务执行后立即设置所有常春藤设置。 最后一个是我的问题。 由于Jenkins的构建正在进行,我想用完全清理的缓存开始构建每个构建,我使用取决于Jenkins执行器编号的自定义缓存设置。 缓存被标记为cache-0至cache-5 。 但是,由于
  • 问题是您只为构建脚本依赖项声明了存储库,但没有为常规依赖项声明存储库。 (换句话说,您需要一个顶级repositories块。)此外, dependencies块应始终位于android块之外,因为它是与Android插件无关的核心Gradle功能。 The problem is that you only declared a repository for build script dependencies, but none for regular dependencies. (In other wor ...
  • 你可以通过这样做在你的构建中排除它 libraryDependencies ++= Seq( "some" % "myCommonLib" % "1.0" excludeAll( ExclusionRule(organization = "yourOrganisation", name = "dependency name"), ... ) 这里有必要的文件: http : //www.scala-sbt.org/0.12.2/api/sbt/ExclusionRule.htm ...
  • 第一个ivy:cachepath没有定义conf,它解析所有配置,因此包含每个模块。 第二个ivy:cachepath只请求conf编译。 因此,显然包括声明为conf="compile" ( conf="compile->compile"同义词)的conf="compile->compile" 。 并且还包括没有任何conf属性的依赖项,因为默认conf为*->* 。 有关依赖项配置的更多文档: http://ant.apache.org/ivy/history/latest-milestone/ivyf ...
  • 您应该zip / tar目录并创建以下设置: http://myrepo.com:8080/artifactory/simple/myrepo/ fizz/ buzz/ 1.7/ buzz-1.7.jar resources-1.7.zip ivy-1.7.xml 在您的ivy.xml中,您可以将每个文件声明为此模块的发布,如下所示:
  • 我有同样的问题,并从Grails用户列表上的Ian Roberts得到了这个答案对我有用: def myCL = new URLClassLoader([new File( "${basedir}/lib/the.jar" ).toURI().toURL()] as URL[], org.apache.ivy.plugins.repository.AbstractRepository.classLoader) resolver myCL.loadCla ...
  • 常ivy:retrieve 任务具有删除不再相关的依赖关系的sync属性。 此外,做一个clean and build帮助。 The ivy:retrieve task has a sync property which removes not longer relevant dependencies. Also, doing a clean and build helps.
  • 通过该项目,您可以获取所有类路径条目。 我经历了并排除了常春藤条目。 然后我用正确的类路径和属性文件重新添加它们。 现在,路径不包括$ {ivyproject_loc}和$ {project_loc}。 代码如下: protected void changeIvyClasspath(IProject project, IProgressMonitor monitor) throws CoreException { if(project.hasNature(JavaCore.NATURE_ID)){ ...
  • Groovy有一个方便的@Grab注释,允许在运行时动态地包含依赖项。 它内部使用常春藤,可以访问Ivy / Maven存储库。 有关这方面的更多信息,请访问: http : //groovy.codehaus.org/Grape 该网站的一个例子: @Grab(group='org.springframework', module='spring', version='2.5.6') import org.springframework.jdbc.core.JdbcTemplate 常春藤集成的另一个选 ...
  • 你不能这样做。 javac编译器根本不理解嵌套在JAR中的JAR。 这是OSGi框架的运行时功能。 要构建这些API,您必须提取内部JAR并将其放入构建时类路径中。 但是,您仍然可以在运行时以您希望的方式使用嵌套JAR。 You can't do this. The javac compiler simply does not understand JARs nested inside JARs. That is a runtime feature of the OSGi Framework. To bui ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)