Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my static logger solution. Useful for ALL projects not only services:</p> <p>Application start with: </p> <pre><code>MyLog.Reset(); </code></pre> <p>Yhen every static or nonstatic method starts with:</p> <pre><code>System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(); MyLog.Log("", stackTrace.GetFrame(0).GetMethod().DeclaringType.ToString(), stackTrace.GetFrame(0).GetMethod().Name, 0); </code></pre> <p>The result is a graphviz diagram source and looks like this: Please note that a last closing curly bracket shuld be added by hand when you copy the text from log.text to generate a GraphViz diagram.</p> <pre><code>digraph G{arrowsize=2.0; ratio=fill; node[fontsize=24];graph [fontsize=24] edge [fontsize=24] node [fontsize=24] ranksep = 1.5 nodesep = .25 edge [style="setlinewidth(3)"]; subgraph cluster_Riogrande_UI { node [style=filled]; label = "Riogrande_UI"; color=red subgraph cluster_UsersForm { node [style=filled]; _ctor_UF; label = "UsersForm"; color=blue }} subgraph cluster_Riogrande_DL { node [style=filled]; label = "Riogrande_DL"; color=red subgraph cluster_DataAccessUsers { node [style=filled]; _ctor_DAU; label = "DataAccessUsers"; color=blue }} _ctor_UF -&gt; _ctor_DAU; } </code></pre> <p>This is the diagram resulted from <a href="http://www.graphviz.org/Download..php" rel="nofollow noreferrer">GraphViz</a>:</p> <p><img src="https://i.stack.imgur.com/m6QKm.png" alt="The result"></p> <p>This is the class I use:</p> <pre><code>namespace Riogrande { public class MyLog { private static int MaximAcceptedLevel = 5; private static string lastMethodName = string.Empty; private static string filePath = "log.txt"; public static void Log(string namespaceName, string className, string methodName, int logLevel) { if (logLevel &lt; MaximAcceptedLevel) using (StreamWriter w = File.AppendText(filePath)) { string namespceName = className.Substring(0, className.LastIndexOf('.')).Replace('.', '_'); if (className.Contains('.')) { className = className.Substring(className.LastIndexOf('.') + 1); } if (className.Contains('+')) { className = className.Substring(0, className.LastIndexOf('+')); } className = className.Replace('.', '_'); string cls = ""; for (int i = className.Length-1; i &gt; -1; i--) { if (Char.IsUpper(className[i])) { if (cls.Length &lt; 3) { cls = className[i] + cls; } } } string currentMethodName = methodName.Replace('.', '_') + "_" + cls; w.WriteLine("subgraph cluster_" + namespceName + " { node [style=filled]; label = \"" + namespceName + "\"; color=red "); w.WriteLine("subgraph cluster_" + className + " { node [style=filled]; " + currentMethodName + "; label = \"" + className + "\"; color=blue }}"); if (!string.IsNullOrEmpty(lastMethodName)) { w.WriteLine(lastMethodName + " -&gt; " + currentMethodName + ";"); } lastMethodName = currentMethodName; } } public static void Reset() { File.Delete(filePath); using (StreamWriter w = File.AppendText(filePath)) { w.WriteLine("digraph G{arrowsize=2.0; ratio=fill; node[fontsize=24];graph [fontsize=24] edge [fontsize=24] node [fontsize=24] ranksep = 1.5 nodesep = .25 edge [style=\"setlinewidth(3)\"]; "); w.WriteLine(); } } } } </code></pre> <p>The solution does not provide a small size file but you can implement this option in the same class.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload