log4net记录日志的难题
C#.net做了一个windows service服务程序。
在本地电脑服务里安装好以后,执行
config文件里面配置log的路径是 \\计算机名\backup\log的时候,
log文件可以正常记录。
如果把路径写成 \\10.15.48.21\\backup\log的时候,log文件就什么也写不进去,
一直是 0字节。
主要是本地磁盘空间不够,想写到另外一台电脑上。
可是用ip访问,和用电脑名访问结果不一样。
ps 本地电脑和另外一台电脑 属于同一个域。
ps 如果不是windows service服务程序,而是一般的exe程序,
路径设置成 \\10.15.48.21\\backup\log也可以正常记录log。
集思广益,高分等着你来拿。
[解决办法]
不能使用相对路径嘛??
[解决办法]
你的日记记录有多少条,存一个都不够吗,如果本地可以先写好的话,然后上传到另外那台机器
1、FTP上传下载,参考:
http://www.xue5.com/itedu/200802/108602.html
2、WebRequest上传下载
http://www.csharpwin.net/ddwstp/net/csharp/4851dr5889.shtml
3、WebClient上传下载
http://www.cnblogs.com/jh8848/articles/804167.html
[解决办法]
如果非要直接在其他机器上直接写的话,你可以先把远程目录转换为本地映射然后写,写完后把映射删掉,下面是我找的类
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace IISWatcher
{
[StructLayout(LayoutKind.Sequential)]
public class NetMappingDrive
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
//如果正确,返回值是0;否则错误。网络访问错误代码53。
[DllImport( "mpr.dll ", EntryPoint = "WNetAddConnection2 ")]
public static extern uint WNetAddConnection2([In] NetMappingDrive lpNetResource, string lpPassword, string lpUsername, uint dwFlags);
[DllImport( "Mpr.dll ")]
public static extern uint WNetCancelConnection2(string lpName, uint dwFlags, bool fForce);
public NetMappingDrive(string LocalDrive, string NetPath,string Username,string Password)
{
this.dwScope = 2;
this.dwType = 1;
this.dwDisplayType = 3;
this.dwUsage = 1;
this.LocalName = LocalDrive;
this.RemoteName = NetPath;
this.Provider = null;
}
public uint CreateDrive(string Username,string Password)
{
return WNetAddConnection2(this, Password, Username, 0);
}
public uint DeleteDrive()
{
return WNetCancelConnection2(this.LocalName, 1, true);
}
}
//添加映射网络驱动器调用的代码如下:
//NETRESOURCE myNetResource = new NETRESOURCE();
//myNetResource.dwScope = 2; //2:RESOURCE_GLOBALNET
//myNetResource.dwType = 1 ; //1:RESOURCETYPE_ANY
//myNetResource.dwDisplayType = 3; //3:RESOURCEDISPLAYTYPE_GENERIC
//myNetResource.dwUsage = 1; //1: RESOURCEUSAGE_CONNECTABLE
//myNetResource.LocalName = "T: ";
//myNetResource.RemoteName = yourNetworkPath;
//myNetResource.Provider = null;
//uint nret = WNetAddConnection2( myNetResource, pwd, username, 0);
//
////删除映射网络驱动器调用的代码如下:
//uint nret = WNetCancelConnection2( yourNetDriveName, 1, true);
[解决办法]
如果非要直接写远程的话,可以先把远程目录转换为本地映射,然后进入,写入写完后把映射删掉
下面是我找的类
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace IISWatcher
{
[StructLayout(LayoutKind.Sequential)]
public class NetMappingDrive
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
//如果正确,返回值是0;否则错误。网络访问错误代码53。
[DllImport( "mpr.dll ", EntryPoint = "WNetAddConnection2 ")]
public static extern uint WNetAddConnection2([In] NetMappingDrive lpNetResource, string lpPassword, string lpUsername, uint dwFlags);
[DllImport( "Mpr.dll ")]
public static extern uint WNetCancelConnection2(string lpName, uint dwFlags, bool fForce);
public NetMappingDrive(string LocalDrive, string NetPath,string Username,string Password)
{
this.dwScope = 2;
this.dwType = 1;
this.dwDisplayType = 3;
this.dwUsage = 1;
this.LocalName = LocalDrive;
this.RemoteName = NetPath;
this.Provider = null;
}
public uint CreateDrive(string Username,string Password)
{
return WNetAddConnection2(this, Password, Username, 0);
}
public uint DeleteDrive()
{
return WNetCancelConnection2(this.LocalName, 1, true);
}
}
//添加映射网络驱动器调用的代码如下:
//NETRESOURCE myNetResource = new NETRESOURCE();
//myNetResource.dwScope = 2; //2:RESOURCE_GLOBALNET
//myNetResource.dwType = 1 ; //1:RESOURCETYPE_ANY
//myNetResource.dwDisplayType = 3; //3:RESOURCEDISPLAYTYPE_GENERIC
//myNetResource.dwUsage = 1; //1: RESOURCEUSAGE_CONNECTABLE
//myNetResource.LocalName = "T: ";
//myNetResource.RemoteName = yourNetworkPath;
//myNetResource.Provider = null;
//uint nret = WNetAddConnection2( myNetResource, pwd, username, 0);
//
////删除映射网络驱动器调用的代码如下:
//uint nret = WNetCancelConnection2( yourNetDriveName, 1, true);