Qué tal?
En muchas ocasiones, en el desarrollo, puedes trabajar con muchos servidores (por ejemplo, aplicaciones web desplegadas en muchos servidores IIS) o muchos workstations (una aplicación Windowforms desplegada con ClickOnce en muchos equipos), y puede necesitarse validar la configuración del equipo, tener una utilidad de diagnóstico puede ser muy útil, para determinar si la configuración del equipo es correcta, y puede minimizar el tiempo de troubleshooting.
La idea viene de un dead project, que estaba en Codeplex:
Y para
ASP.NET una referencia de Omar Al Zabir
Podemos fijarnos en el instalador de Sql Server 2008 R2 installer que hace lo siguiente: SQL Server Setup valida que la configuración del equipo está completa antes de iniciar la instalación). Lástima no liberen código del instalador, se aprenderían técnicas.
Por ejemplo, dada una configuración app.config (o web.config)
<connectionStrings>
<add name="ConnectionStrings.SqlServer"
connectionString="Data Source="
providerName="SqlClient"/>
<add name="ConnectionStrings.SqlServer.Navision"
connectionString="Data Source=NAVISION\SQL2014;"
providerName="SqlClient"/>
</connectionStrings>
<appSettings>
<add key="ModoPruebas" value="S" />
<add key="IntegracionEAI.RutaLogs" value="\\sql-pre\logs\Log.IntegracionEAI"/>
<add key="RutaFicheros.Envios" value="\\sql-pre\logs\Envios"/>
<add key="RutaFicheros.Descargas" value="\\sql-pre\logs\Descargas\"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true" indentsize="4"/>
<sources>
<source name="System.Net">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add
name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Company\Logs\Project\System.Net.trace.log"
traceOutputOptions = "ProcessId, DateTime" />
</sharedListeners>
<switches>
<!-- MSDN: 4 verbose Information, Information 3, Warning 2, Error 1, -->
<add name="System.Net" value="Verbose" />
<add name="System.Net.Cache" value="Verbose" />
</switches>
</system.diagnostics>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServiceSendSMSD">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxxxxxxxxxxx:444/WebServiceSendSMSD/ServiceSendSMSD.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceSendSMSD"
contract="xxxxx.IServiceSendSMSD" name="BasicHttpBinding_IServiceSendSMSD" />
</client>
</system.serviceModel>
</configuration>
Podría hacerse algo así, comprobar las conexiones, las rutas físicas, etc
También poder acceder programáticamente a sharedListeners de diagnostics y comprobar el valor de sharedListeners. O modificar las direcciónes de los endpoints, programáticamente .
public static partial class Comprobaciones
{
public static bool TestConexionSQL()
{
try
{
using (var con = new System.Data.SqlClient.SqlConnection(CONEXION_SQL))
{
con.Open();
con.Close();
}
return true;
}
catch (Exception ex)
{
Trace.WriteLine("Error Test: " + ex.Message);
return false;
}
}
public static bool TestPaths()
{
bool allPathOK = true;
foreach (string key in ConfigurationManager.AppSettings.AllKeys)
{
string value = ConfigurationManager.AppSettings[key];
if (value.StartsWith(@"\\"))
{
if (!Directory.Exists(value) && !File.Exists(value))
{
Trace.WriteLine("Invalid path: " + key + "=" + value);
allPathOK = false;
}
}
// value = "../" FullPath ...
if (value.StartsWith(@"C:\") || value.StartsWith(@"D:\"))
{
if (!Directory.Exists(value) && !File.Exists(value))
{
Trace.WriteLine("Invalid path: " + key + "=" + value);
allPathOK = false;
}
}
}
if (allPathOK)
return true;
return false;
}
Otras opciones más avanzadas:
Tenéis alguna experiencia?
Gracias de antemano.